插入排序
/*** Definition for singly-linked list.* struct ListNode {* int val;* ListNode *next;* ListNode() : val(0), next(nullptr) {}* ListNode(int x) : val(x), next(nullptr) {}* ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/class Solution {public:ListNode* insertionSortList(ListNode* head) {if(head==nullptr||head->next==nullptr){return head;}ListNode* head1=head;ListNode* head2=head;while(head->next!=nullptr){head=head->next;while(head1!=head){if(head1->val>head->val){int temp=head1->val;head1->val=head->val;head->val=temp;}head1=head1->next;}head1=head2;}return head2;}};
