美文网首页
147-insertion-sort-list

147-insertion-sort-list

作者: Twopothead | 来源:发表于2019-07-20 22:51 被阅读0次

147

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

struct ListNode* insertionSortList(struct ListNode* head){
    for (struct ListNode *p = head; p != NULL; p=p->next)
    {
        int key = p->val;
        struct ListNode *q = head;
        while (q && q!=p)
        {
            if(q->val>key){
                int a = q->val;
                q->val = key;
                key = a;
            }
            q=q->next;
        }
        p->val = key;
    }
    return head;
}

网友评论

      本文标题:147-insertion-sort-list

      本文链接:https://www.haomeiwen.com/subject/teeplctx.html