【发布时间】:2016-10-01 18:18:09
【问题描述】:
我有一个链表,我必须确保无论链表的最大数量是多少,我都将它放在链表的末尾。我不确定我做错了什么。谁能解释一下?
void moveAllMaxAtEnd(list A) {
int max=0;
link tmp=A->first;
link curr=tmp->next;
int i,count=0;
while(curr!=NULL){ //This first while is where I find the max item
if(curr->item>=max){
max=curr->item;
count++;
}
else{
curr=curr->next;
}
}
link prev=A->first;
link curr1=prev->next;
link tmp1;
while(curr1->next!=NULL){ //In this loop I am trying to put the
if(curr1->item==max){ //max items at the end.
prev->next=curr1->next;
tmp1=prev->next;
prev->next=curr1->next;
curr1->next=tmp1;
}
else{
prev=prev->next;
curr1=curr1->next;
}
}
}
【问题讨论】:
标签: c linked-list