Using insertion sort on a singly linked list

前端 未结 7 1129
春和景丽
春和景丽 2021-02-06 10:11

So I have an assignment where I\'m giving a random list of number and I need to sort them using insertion sort. I must use a singly linked list. I looked around at other posts b

7条回答
  •  温柔的废话
    2021-02-06 11:03

    Think about this - if the list is empty, temp will initially be NULL, so you get undefined behavior when you do temp->next = head;.

    Try some debugging, it will surely help. You'll probably either want to keep the previous node as well, so you can insert afterwards, or look 2 nodes forward.

提交回复
热议问题