js数据结构描述--栈

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('张三');
stack.push('李四');
stack.push('王五');

stack.pop();
stack.push('赵六');
alert(stack.show());
原文地址:https://www.cnblogs.com/liwuming/p/4488956.html