Skip to content

Instantly share code, notes, and snippets.

@romaintailhurat
Last active November 8, 2017 09:01
Show Gist options
  • Save romaintailhurat/78d24c702ca3de47ebf53235546ec23f to your computer and use it in GitHub Desktop.
Save romaintailhurat/78d24c702ca3de47ebf53235546ec23f to your computer and use it in GitHub Desktop.

Revisions

  1. romaintailhurat revised this gist Nov 8, 2017. 1 changed file with 0 additions and 15 deletions.
    15 changes: 0 additions & 15 deletions stack.js
    Original file line number Diff line number Diff line change
    @@ -18,18 +18,3 @@ class Stack {
    return resultingArray[0];
    }
    }

    const st = new Stack()
    st.push(12);
    st.push(4);
    st.push(66);

    console.log(st);

    st.pop();

    console.log(st);

    st.push("test");

    console.log(st);
  2. romaintailhurat created this gist Nov 8, 2017.
    35 changes: 35 additions & 0 deletions stack.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@

    /*
    Stack, array implementation
    http://www.cs.usfca.edu/~galles/visualization/StackArray.html
    */
    class Stack {
    constructor() {
    this._stack = [];
    this._index = -1;
    }
    push(value) {
    this._index++;
    this._stack[this._index] = value;
    }
    pop() {
    const resultingArray = this._stack.splice(this._index, 1);
    this._index--;
    return resultingArray[0];
    }
    }

    const st = new Stack()
    st.push(12);
    st.push(4);
    st.push(66);

    console.log(st);

    st.pop();

    console.log(st);

    st.push("test");

    console.log(st);