Advertisement
cwchen

[Go][excerpt] list push

Nov 21st, 2017
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.29 KB | None | 0 0
  1. // Excerpt
  2. // Push data into the tail of the list
  3. func (list *List) Push(data interface{}) {
  4.     node := node{data: data, next: nil, prev: nil}
  5.     if list.head == nil {
  6.         list.head = &node
  7.         list.tail = &node
  8.     } else {
  9.         list.tail.next = &node
  10.         node.prev = list.tail
  11.         list.tail = &node
  12.     }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement