RosettaCodeData/Task/Collections/M2000-Interpreter/collections-2.m2000

37 lines
999 B
Plaintext

Module CheckStack {
\\ ordered collection: Stack
\\ we can add values to top or bottom,
\\ we can move values to and from top
A=Stack:=100,300,600,800,900
Print StackItem(A, 2)=300, Len(A)=5
Stack A {
\\ push to bottom (or end)
Data 2000, 4000
}
Print StackItem(A, 7)=4000, Len(A)=7
Stack A {
\\ pop from top
Read X, Y
Print X=100, Y=300
}
Print StackItem(A,5)=4000, Len(A)=5
Stack A {
\\ push to top
Push 2, 1
Stack ' display stack items
}
\\ we can make a new stack merging other stacks
A=Stack(A, stack:=5000,6000,7000)
Print Len(A)=10
Stack A {
Shift 1,-Len(A) ' Reverse order
Stack ' Display
}
Stack A {Drop 8}
Print Len(A)=2
Flush ' empty current stack
Stack A ' dump A to current stack
Print Stack.Size=2, Len(A)=0
}
CheckStack