Κυριακή 3 Ιουλίου 2022

Using Stack Objects as FIFO and LIFO

From  http://rosettacode.org/wiki/Queue/Usage#M2000_Interpreter 

Module CheckStackAsLIFO {

	a=stack
Stack a {
Push 1, 2, 3
Print number=3
Print number=2
Print number=1
Print Empty=True
Push "A", "B", "C"
Print letter$="C"
Print letter$="B"
Print letter$="A"
Print Empty=True
Push 1,"OK"
}
Print Len(a)=2, StackItem(a, 2)=1, StackItem$(a, 1)="OK"
Print StackType$(a, 1)="String", StackType$(a,2)="Number"
}
CheckStackAsLIFO
Module CheckStackAsFIFO {
a=stack
Stack a {
Data 1, 2, 3
Print number=1
Print number=2
Print number=3
Print Empty=True
Data "A", "B", "C"
Print letter$="A"
Print letter$="B"
Print letter$="C"
Print Empty=True
Push 1,"OK"
}
Print Len(a)=2, StackItem(a, 2)=1, StackItem$(a, 1)="OK"
Print StackType$(a, 1)="String", StackType$(a,2)="Number"
}
CheckStackAsFIFO