Last active
September 2, 2015 18:10
-
-
Save hoitomt/f343f322410a1663d0b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 @data to reference node4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment