Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Numberqueue() {
- this.stack = [];
- }
- Numberqueue.prototype.enqueue = function(item) {
- if (typeof item !== "number") throw Error("not a number");
- this.stack.push(item);
- console.log(item + " is added to the top of the stack");
- };
- Numberqueue.prototype.dequeue = function() {
- if (this.stack.length == 0) throw Error("stack is empty");
- console.log(this.stack[this.stack.length - 1] + " is removed from the stack");
- this.stack.pop();
- };
- let prototypeStack = new Numberqueue();
- prototypeStack.enqueue(2);
- prototypeStack.dequeue();
- function NumberqueueInclosed() {
- this.stack = [];
- this.enqueueIC = function(item) {
- if (typeof item !== "number") throw Error("not a number");
- this.stack.push(item);
- console.log(item + " is added to the top of the IC stack");
- };
- this.dequeueIC = function() {
- if (this.stack.length == 0) throw Error("IC stack is empty");
- console.log(
- this.stack[this.stack.length - 1] + " is removed from the IC stack"
- );
- this.stack.pop();
- };
- }
- let inclosedStack = new NumberqueueInclosed();
- inclosedStack.enqueueIC(2)
- inclosedStack.dequeueIC();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement