Files
Nasal-Interpreter/test/stack.nas
Valk Richard Li 125fc8a9fe bug fixed & test file changes
compare operators now run more efficiently.
2021-03-31 20:59:13 +08:00

37 lines
651 B
Plaintext

# lib stack.nas
# valkmjolnir 2021/3/31
var stack=func()
{
var _={next:nil};
return
{
push:func(elem)
{
_.next={elem:elem,next:_.next};
return;
},
pop:func()
{
var tmp=_.next;
if(tmp!=nil)
_.next=tmp.next;
return;
},
top:func()
{
var tmp=_.next;
if(tmp!=nil)
return tmp.elem;
return nil;
},
clear:func()
{
_.next=nil;
},
empty:func()
{
return _.next==nil;
}
};
}