list_node * selection_sort(list_node * head) { //////在下面完成代码 list_node *cur = head; while (cur) { list_node *tmp = cur; list_node *start = cur->next; while (start) { if (start->val < tmp->val) { tmp = start; } start = start->next; } if (tmp != cur) { int t_val = cur->val; cur->val = tmp->val; tmp->val = t_val; } cur = cur->next; } return head; } ```递归算法,需merge函数
list_node * selection_sort(list_node * head)
{
//////在下面完成代码
if(!head||!head->next) return head; list_node*pslow=head; list_node*pfast=head->next; while(pfast&&pfast->next){ pslow=pslow->next; pfast=pfast->next->next; } list_node*h2=pslow->next; pslow->next=NULL; list_node*p1=selection_sort(head); list_node*p2=selection_sort(h2); return mergeList(p1,p2);
}