Skip to content

Commit

Permalink
[Add] Stack
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunSangHan committed Apr 22, 2020
1 parent c7969dd commit 69ffb85
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions data_structure/stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function Stack () {
this.data = [];
}

Stack.prototype.push = function (newData) {
this.data.push(newData);
}

Stack.prototype.pop = function () {
return this.data.pop() || null;
}

Stack.prototype.getSize = function () {
return this.data.length;
}

const stack = new Stack();


stack.push(3);
stack.push(2);
stack.push(4);
stack.push(6);
console.log(stack.data);
console.log(stack.getSize());
stack.pop();
stack.pop();
console.log(stack.data);
stack.pop();
console.log(stack.getSize());

0 comments on commit 69ffb85

Please sign in to comment.