class Solution {
public:
/**
* @param head: The first node of linked list.
* @return: The head of linked list.
*/
ListNode *insertionSortList(ListNode *head) {
int a[10000];
int i=1;
while(head!=NULL)
{
a[i]=head->val;
i++;
head=head->next;
}
sort(a+1,a+i);
ListNode *ss;
ss=new ListNode;
ListNode *dd;
dd=ss;
for(int j=1;j<i;j++)
{
ListNode *xx;
xx=new ListNode;
xx->val=a[j];
ss->next=xx;
ss=xx;
}
if(dd==NULL)
return dd;
else
return dd->next;
// write your code here
}
};
链表插入排序 - C++
最新推荐文章于 2022-09-23 15:23:55 发布