Data structure description js - Stack

function Stack(){
	this.dataStore = [];
	this.top = 0;
	this.pop = pop;
	this.push = push;
	this.peek = peek;
	this.clear = clear;
	this.length = length;
	this.show = show;
}

function push(element){
	this.dataStore[this.top++] = element;
}

function pop(){
	this.dataStore[--this.top];
}

function peek(){
	return this.dataStore(this.top - 1);
}

function clear(){
	this.dataStore = [];
}

function length(){
	return this.dataStore.length;
}

function show(){
	return this.dataStore;
}
	
var stack = new Stack();
stack.push ( 'John Doe');
 stack.push ( 'John Doe');
 stack.push ( 'Wangwu');

stack.pop();
 stack.push ( 'Zhao six');
alert(stack.show());

 

Intelligent Recommendation

JS description data structure and algorithm

JS description data structure and algorithm 1.1 2. Array splice (start, length, inserted, or deleted entries), taken 0 is the length of insertion (greater than 0 to delete, delete the item returned), ...

Data Structure - Stack -JS Implement a Stack Structure

Data Structure - Stack -JS Implement a Stack Structure Foreword: The data structure and algorithm are out of language, such as POP, and Push can be used in JS, but other languages ​​have? Not necessar...

C ++ implementation of stack data structure (list description)

A stack is a very important data structure can be seen as a plug-linear table at one end and deletion are performed. Therefore, it is considered stack element is "last out." Since the stack ...

More Recommendation

Data structure learning-chain description of stack

After learning the array description of the stack, A Wei wants to learn the chain description of the stack and describe QAQ According to the analysis, it is more efficient to use the left end of the l...

Data structure Java language description stack operation

1. Description of the stack The stack is a structure for storing data in an advanced format. 2. The implementation of the stack There are two ways to implement stack operations: linear stack and chain...

## JavaScript description of data structure and algorithm-stack

JavaScript description of data structure and algorithm-stack Note: The following parts are all learning content and notes of "JavaScript Description of Data Structures and Algorithms". 1. Im...

[Js4agls] Data structure JavaScript description-stack

List item The stack is a last-in-first-out (LIFO) data structure. All we can manipulate are the top elements of the stack. Deleting a top element is calledUnstackorPop stackAnd add an element calledPu...

[Data Structure and Algorithm (Java Description)] Stack

Source from books "Data Structure and Algorithm (Java Description)" Deng Junhui Machinery Industry Press Stack The stack is a special container that stores an object. When inserting and dele...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top