放在数组里暴力排序再赋值即可
int cmp(const void*e1,const void*e2)
{
return *(int*)e1-*(int*)e2;
}
struct ListNode* sortList(struct ListNode* head){
if(head==NULL)return NULL;
int nums[50000];
struct ListNode*node=head;
struct ListNode*ret=head;
int n=0;
while(node)
{
nums[n++]=node->val;
node=node->next;
}
qsort(nums,n,sizeof(nums[0]),cmp);
int a=0;
while(ret)
{
ret->val=nums[a++];
ret=ret->next;
}
return head;
}
本文介绍了一个使用C语言编写的函数sortList,它对链表的节点值进行整数数组的暴力排序,通过qsort函数实现快速排序算法。

2154

被折叠的 条评论
为什么被折叠?



