aardio数据结构之队列结构
//queue队列结构//队列的特点:先进先出
import console;
class queue{
ctor(){
this.items = {}
};
//排队
enqueue = function(element){
..table.push(this.items,element);
}
//出列
dequeue = function(){
return ..table.shift(this.items);
}
//前面
front = function(){
return this.items;
}
//清空栈
clear = function(){
this.items = {};
}
//是否为空栈
isEmpty = function(){
return !#this.items;
}
//大小
size = function(){
return #this.items;
}
//打印队列
print = function(){
return ..string.join(this.items,",")
}
}
//实例化栈
var Queue = queue();
//排队
Queue.enqueue("A");
Queue.enqueue("B");
Queue.enqueue("C");
Queue.enqueue("D");
//大小
console.log(Queue.size())
//是否为空栈
console.log(Queue.isEmpty())
//出队
console.log(Queue.dequeue())
console.log(Queue.dequeue())
//前面
console.log(Queue.front())
//大小
console.log(Queue.size())
//打印全部队列数据
console.log(Queue.print())
console.pause(true);
页:
[1]