Untitled
plain_text
2 months ago
552 B
1
Indexable
Never
Node* sortList(Node *head){ Node* tmp=head; int cnt1=0,cnt2=0,cnt3=0; while(tmp!=NULL){ if(tmp->data==0) cnt1++; if(tmp->data==1) cnt2++; if(tmp->data==2) cnt3++; tmp=tmp->next; } tmp=head; while(tmp!=NULL){ if(cnt1>0){ tmp->data=0; cnt1--; }else if(cnt2>0){ tmp->data=1; cnt2--; }else if(cnt3>0){ tmp->data=2; cnt3--; } tmp=tmp->next; } return head; }