输出单链表最大值的结点,用C,简单写一下求最大值的函数吧。拜托大神了
参考我的博客数据结构(一)、数据结构(二)
http://blog.csdn.net/lixiaogang_theanswer/article/details/70233768
/****链表节点排序****/ ===按从小到大顺序排序;
/****链表节点排序****/
void SListNodeSort(SLIST*pHead)
{
SLIST *pPre = NULL;
SLIST *pCur = NULL;
/***两个指针就可以实现****/
SLIST *pRear = NULL;
SLIST pTemp ={0,NULL};
pPre=pHead->next;
//pRear = pHead->next->next;
pRear = pHead->next;
pCur = pRear;
while (pPre!=NULL)
{
pRear=pPre->next;
while (pRear!=NULL)
{
if ((pPre->id)>(pRear->id))
{
pTemp.id = pPre->id;
pPre->id = pRear->id;
pRear->id = pTemp.id;
}
pRear = pRear->next;
}
pPre=pPre->next;
//pRear=pCur->next->next;
}
}
楼主,我重新给你写了一个函数:输出链表中值最大的节点值
/****求链表中的值最大的节点****/
void SListNodeMaxVar(SLIST *pHead)
{
SLIST *pPre = NULL;
SLIST *pCur = NULL;
SLIST pMax;
if (pHead == NULL)
{
return;
}
pPre = pHead;
pMax.id = pHead->next->id;
pCur = pHead->next->next;
while (pCur != NULL)
{
if (pCur->id > pMax.id)
{
pMax.id = pCur->id;
}
pCur = pCur->next;
}
printf ("pMax->id = %d\n",pMax.id);
}