aardio数据结构之栈结构
Code here//stack栈结构
//栈的特点:先进后出
import console;
class stack{
ctor(){
this.items = {};
};
//入栈
push = function(element){
..table.push(this.items,element);
}
//出栈
pop = function(){
return ..table.pop(this.items);
}
//末位
peek = function(){
return this.items[#this.items];
}
//是否为空栈
isEmpty = function(){
return !#this.items;
}
//大小
size = function(){
return #this.items;
}
//清空栈
clear = function(){
this.items = {};
}
}
//实例化栈
var Stack = stack();
//入栈
Stack.push("A");
Stack.push("B");
Stack.push("C");
Stack.push("D");
//出栈
Stack.pop()
//末位
console.log(Stack.peek())
//大小
console.log(Stack.size())
//是否为空栈
console.log(Stack.isEmpty())
console.log(Stack.clear())
//大小
console.log(Stack.size())
console.pause(true);
页:
[1]