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
pointersto manipulate LinkedList pre,cur,next- figure out the
timeandorderto update those pointers dummy nodeto 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 LinkedListrotatethe 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
recursionandHashMaptodeep copya LinkedList DoubleLinkedListimplemementation
- reverse