1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
struct ListNode* (struct ListNode* head){ struct ListNode* dummyHead = (struct ListNode*)malloc(sizeof(struct ListNode)); dummyHead->next = head; if (head == NULL) { return head; } struct ListNode* pre = NULL; struct ListNode* cur = head; struct ListNode* next = NULL; while (cur->next != NULL) { next = cur->next; if (cur->val <= next->val) { cur = cur->next; }else{ pre = dummyHead; while (pre->next != NULL && pre->next->val <= next->val) { pre = pre -> next; } cur->next = next->next; next->next = pre->next; pre->next = next; } } return dummyHead->next; }
|
近期评论