Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void sort(ListNode* &head,ListNode*cur)
- {
- if(head==NULL||cur->val<=head->val)
- {
- cur->next=head;
- head=cur;
- }
- else{
- ListNode*tmp=head;
- while(tmp->next&&tmp->next->val<cur->val)
- {
- tmp=tmp->next;
- }
- cur->next=tmp->next;
- tmp->next=cur;
- }
- }
- ListNode* insertionSortList(ListNode* head) {
- ListNode*tmp=head,*root=NULL;
- while(tmp)
- {
- ListNode*next=tmp->next;
- sort(root,tmp);
- tmp=next;
- }
- return root;
- }
Add Comment
Please, Sign In to add comment