Skip to content

Instantly share code, notes, and snippets.

@hoitomt
Last active September 2, 2015 18:10
Show Gist options
  • Save hoitomt/f343f322410a1663d0b3 to your computer and use it in GitHub Desktop.
Save hoitomt/f343f322410a1663d0b3 to your computer and use it in GitHub Desktop.
Stack - [a, b, c, d]
Start:
node4 -> node3 -> node2 -> node1
Stack - no idea how many items are in it, only knows the top item
@data = node4
Next - Add a new node to the stack - "push"
push(value)
Use that value to create a new node (New Node)
Take our new node and add a reference to the last existing node - represented by @data
@data = New Node, which essentially becomes node5
Now
Stack
@data = node5
POP
Now
node5 -> node4 -> node3 -> node2 -> node1
pop
return the value from node5
update the reference of node5 to nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment