void populate(Node* &tail,Node* curr){
tail->next=curr;
tail = curr;
}
Node* sortList(Node *head){
Node* zerohead = new Node(-1);
Node* zerotail = zerohead;
Node* onehead = new Node(-1);
Node* onetail = onehead;
Node* twohead = new Node(-1);
Node* twotail = twohead;
Node* curr = head;
while(curr!=NULL){
int value = curr->data;
if(value==0){
populate(zerotail,curr);
}
else if(value==1){
populate(onetail,curr);
}
else if(value==2){
populate(twotail,curr);
}
curr = curr->next;
}
// merge 3 list
if(onehead->next!=NULL){
zerotail->next = onehead->next;
}
else{
zerotail->next = twohead->next;
}
onetail->next = twohead->next;
twotail->next = NULL;
head = zerohead ->next;
delete(zerohead);
delete(onehead);
delete(twohead);
return head;
}