Skip to content

Instantly share code, notes, and snippets.

@hoitomt
Last active September 2, 2015 18:10

Revisions

  1. hoitomt revised this gist Sep 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Stack
    Original file line number Diff line number Diff line change
    @@ -23,4 +23,4 @@ Now

    pop
    return the value from node5
    update the reference of node5 to nil
    update @data to reference node4
  2. hoitomt revised this gist Sep 2, 2015. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions Stack
    Original file line number Diff line number Diff line change
    @@ -16,3 +16,11 @@ Now
    Stack
    @data = node5


    POP
    Now
    node5 -> node4 -> node3 -> node2 -> node1

    pop
    return the value from node5
    update the reference of node5 to nil
  3. hoitomt created this gist Sep 2, 2015.
    18 changes: 18 additions & 0 deletions Stack
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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