|
- typedef struct Node
- {
- int i;
- struct Node *next;
- }NodeDef;
- /*找出链表中,p->i最大者,并取出链表。*/
- NodeDef *findmax(NodeDef *head)
- {
- NodeDef *premax,*max,*pretmp,*tmp;
- max=head;
- pretmp=head;
- tmp=head->next;
- premax=NULL;
- while(tmp!=NULL)
- {
- if((max->i)<(tmp->i))
- {
- max=tmp;
- premax=pretmp;
- }
- pretmp=tmp;
- tmp=tmp->next;
- }
- if(max!=head)
- premax->next=max->next;
- else
- head=head->next;//函数返回后,head又变回原来的了?:help
- return max;
- }
复制代码 |
|