请解释一个单链表的插入排序问题
发布网友
发布时间:2022-04-26 09:48
我来回答
共3个回答
热心网友
时间:2022-04-26 11:17
插入排序吧,较小的插入到前面
L一直指向头,每次从头开始遍历,共n^2次,较小值插到前面
第一次是跳过while循环的
热心网友
时间:2022-04-26 12:35
Codes above is all right. But the list to be passed to the function must have a sentinel with a minimum value.
r and q are assistant pointers for inserting node pointed by p, and r points to the head of list L, q points to r's next when every iteration starts. They go ahead until q's id is smaller than p's id, when node p will be inserted. Pointer pre points to the start of non-sored list remained.
Concept of insertion sort is employed in such list sorting. Its time complexity is O(n^2).
热心网友
时间:2022-04-26 14:10
代码是错的.