My question starts from this code.
http://play.golang.org/p/WKcQBWnEG9
As you see, when adding new elements to the list, either to the back or to the front, this code is not updating both of the two pointers in Node struct. One of which points to the next and the other to the previous node.
A.tail= NewNode(input_value, A.tail, nil)
or
A.head = NewNode(input_value, nil, A.head)
works perfect for a singly linked list that only points to next
, so I did the same thing for the doubly linked list and get this error.
In which I try to avoid the nil pointer dereference, creating a temporary variable but I am still getting the same error.
In which I try to condition-test the empty list and do the similar thing and get the same error. And I am stuck at this point.
The main problem is for the structure like doubly linked list
, how do I initialize the nil pointer of the head ?
1. when I want to add new elements to the front
2. thereby when I need to update the second-, third-, fourth-front elements with a newly-inserted head nodes
3. and when I can't update the nil pointer of head node.
I am stuck on this all day.
I would greatly appreciate it!