background
stanford cs gives me some confidence to deal with linked list.
linked list basics
basic pointers as well as previous blog:
a
pointer
stores a reference to another variable(pointee
). what stored insidepointer
is an reference to its pointee’s type.NULL pointer, points to nothing.
pointer assignment
p=q
, makes the two pointers point to the same pointee, namely the two pointers point to the same pointee memory.
it’s a good habit to remember to check the empty list case.
define the Linked-List structure:
|
|
- iterate over the list with a local pointer
|
|
- push a new node to the front of the list
|
|
- build up a list by adding nodes at its head
|
|
which returns a list {1, 2, 3, 4}
- appendNode(), add new node at the tail
|
|
- copyList() recursive
|
|
linked list problems further
- InsertNth()
|
|
- sortedInsert()
|
|
- insertSort()
given as unsorted list, and output with an sorted list
|
|
- append()
append list b to the end of list a
|
|
- frontBackSplit()
given a list, split it into two sublists: one for the front half, one for the back half
|
|
- removeDuplicates()
remove duplicated node from a sorted list
|
|
- moveNode()
given two list, remove the front node from the second list, and push it onto the front of the first.
// a = {1, 2, 3}; b = {1, 2, 3} => a={1, 1, 2, 3}, b={2, 3}
|
|
- alternatingSplit()
given a list, split its nodes into two shorter lists. if we number the elements 0, 1, 2, …, then all the even elements go to the first sublist, and all the odd elements go to tthe second
|
|
- shuffleMerge()
given two list, merge their nodes together to make one list, takign nodes alternatively between the two lists
|
|
- sortedMerge()
given two sorted in incresing order listes, merge into one in increasing order
|
|
- mergeSort()
|
|
- reverse()
|
|
- recursive reverse()
// concerned
|
|