Skip to content

Commit

Permalink
Update 01.Linked-List-Sort.md
Browse files Browse the repository at this point in the history
  • Loading branch information
itcharge committed Jan 13, 2022
1 parent cb7ca44 commit 8b9fbed
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def bubbleSort(self, head: ListNode):
- 使用两个指针 `node_i``node_j``node_i` 既可以用于控制外循环次数,又可以作为当前未排序链表的第一个链节点位置。
- 使用 `min_node` 记录当前未排序链表中值最小的链节点。
- 每一趟排序开始时,先令 `min_node = node_i`(即暂时假设链表中 `node_i` 节点为值最小的节点,经过比较后再确定最小值节点位置)。
- 然后依次比较未排序链表中 `node_j.val``min_node.val` 的值大小。如果 `node_j.val > min_node.val`,则更新 `min_node``node_j`
- 然后依次比较未排序链表中 `node_j.val``min_node.val` 的值大小。如果 `node_j.val < min_node.val`,则更新 `min_node``node_j`
- 这一趟排序结束时,未排序链表中最小值节点为 `min_node`,如果 `node_i != min_node`,则将 `node_i``min_node` 值进行交换。如果 `node_i == min_node`,则不用交换。
- 排序结束后,继续向右移动 `node_i`,重复上述步骤,在剩余未排序链表中寻找最小的链节点,并与 `node_i` 进行比较和交换,直到 `node_i == None` 或者 `node_i.next == None` 时,停止排序。
- 返回链表的头节点 `head`
Expand Down

0 comments on commit 8b9fbed

Please sign in to comment.