2020-11-03 19:27:21 +08:00
|
|
|
# lib queue.nas
|
2021-03-31 20:59:13 +08:00
|
|
|
# valkmjolnir 2021/3/31
|
|
|
|
var queue=func()
|
2020-11-03 19:27:21 +08:00
|
|
|
{
|
2021-08-11 14:54:17 +08:00
|
|
|
var (begin,end)=(nil,nil);
|
2021-10-16 14:07:55 +08:00
|
|
|
return{
|
|
|
|
push:func(elem){
|
|
|
|
var new_node={
|
2021-03-31 20:59:13 +08:00
|
|
|
elem:elem,
|
|
|
|
next:nil
|
|
|
|
};
|
2021-08-11 14:54:17 +08:00
|
|
|
if(begin==nil)
|
|
|
|
begin=end=new_node;
|
2021-10-16 14:07:55 +08:00
|
|
|
else{
|
2021-08-11 14:54:17 +08:00
|
|
|
end.next=new_node;
|
|
|
|
end=new_node;
|
2021-03-31 20:59:13 +08:00
|
|
|
}
|
|
|
|
},
|
2021-10-16 14:07:55 +08:00
|
|
|
pop:func(){
|
2021-08-11 14:54:17 +08:00
|
|
|
if(begin!=nil)
|
|
|
|
begin=begin.next;
|
|
|
|
if(begin==nil)
|
|
|
|
end=nil;
|
2021-03-31 20:59:13 +08:00
|
|
|
},
|
2021-10-16 14:07:55 +08:00
|
|
|
front:func(){
|
2021-08-11 14:54:17 +08:00
|
|
|
if(begin!=nil)
|
|
|
|
return begin.elem;
|
2021-03-31 20:59:13 +08:00
|
|
|
},
|
2021-10-16 14:07:55 +08:00
|
|
|
clear:func(){
|
2021-08-11 14:54:17 +08:00
|
|
|
begin=end=nil;
|
2021-03-31 20:59:13 +08:00
|
|
|
},
|
2021-10-16 14:07:55 +08:00
|
|
|
empty:func(){
|
2021-08-11 14:54:17 +08:00
|
|
|
return begin==nil;
|
2021-03-31 20:59:13 +08:00
|
|
|
}
|
2021-03-03 09:20:42 +08:00
|
|
|
};
|
2020-11-03 19:27:21 +08:00
|
|
|
}
|