Keep in mind that there are two ways to deal with the LinkList very easily.
1. Using the vector to store every item of the list, then we can use the index of the vector to operate the link. That helps a lot.
2. Using three pointers and should understand the theory.(pre, start, then)
start is the beginning that we will reverse at the list.
1-2-3-4 pre = 1, start = 2, then = 3
把then 插入到pre的后面,pre不动,then始终在放到start的后面.
start.next = then.next //把then先拿出来
then.next = pre.next //把then在新位置上前后相连
pre.next = then. // then的前面
then = start.next // then 重新放到start的后面
时间: 2024-10-07 06:47:51