LinkedList - node pointer
data structure
Defination
public class ListNode {
int val;
ListNode next;
public ListNode(int _val) {
this.val = _val;
this.next = null;
}
public ListNode(int _val, ListNode _next) {
this.val = _val;
this.next = _next;
}
}
Notes
- use
pointers
to manipulate LinkedList pre
,cur
,next
- figure out the
time
andorder
to update those pointers dummy node
to simplifymodification
- basic operations
reverse
(pre, cur, next)reorder
(dummy), be careful about the next pointer of each node elementcombine
, be carful about theend(null)
of the LinkedListrotate
the list by k steps, invloved with building a loop and cut a loop
- advanced operations
- reverse
by group or length
, usepre
(only change next pointer),subTail
(only change next pointer),Temp
(keep moving),reverse pointer between subTail and Temp
,insert Temp after pre
- whenever use a dummy node, means use two nodes,
ListNode dummy = new ListNode(-1); ListNode iter = dummy;
- remember to cut the tail at the end of LinkedList,
cur.next = null;
- use
recursion
andHashMap
todeep copy
a LinkedList DoubleLinkedList
implemementation
- reverse