void sort(node **q) { int n; node *cur; cur=*q; if (cur->next==NULL) return; node *ptr,*tmp; cur=cur->next; while(cur!=NULL) { n=0; ptr=cur; tmp=cur->prev; cur=cur->next; while (tmp!=NULL && tmp->data>ptr->data) { n++; tmp=tmp->prev; } if (n) { ptr->prev->next=ptr->next; if (ptr->next!=NULL) ptr->next->prev=ptr->prev; if (tmp==NULL) { tmp=*q; ptr->prev=NULL; ptr->next=tmp; ptr->next->prev=ptr; *q=ptr; } else { tmp=tmp->next; tmp->prev->next=ptr; ptr->prev=tmp->prev; tmp->prev=ptr; ptr->next=tmp; } } } }