Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Stack/Elisa/stack-1.elisa
Normal file
21
Task/Stack/Elisa/stack-1.elisa
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
component GenericStack ( Stack, Element );
|
||||
type Stack;
|
||||
Stack (MaxSize = integer) -> Stack;
|
||||
Empty ( Stack ) -> boolean;
|
||||
Full ( Stack ) -> boolean;
|
||||
Push ( Stack, Element) -> nothing;
|
||||
Pull ( Stack ) -> Element;
|
||||
begin
|
||||
Stack(MaxSize) =
|
||||
Stack:[ MaxSize; index:=0; area=array (Element, MaxSize) ];
|
||||
Empty( stack ) = (stack.index <= 0);
|
||||
Full ( stack ) = (stack.index >= stack.MaxSize);
|
||||
Push ( stack, element ) =
|
||||
[ exception (Full (stack), "Stack Overflow");
|
||||
stack.index:=stack.index + 1;
|
||||
stack.area[stack.index]:=element ];
|
||||
Pull ( stack ) =
|
||||
[ exception (Empty (stack), "Stack Underflow");
|
||||
stack.index:=stack.index - 1;
|
||||
stack.area[stack.index + 1] ];
|
||||
end component GenericStack;
|
||||
25
Task/Stack/Elisa/stack-2.elisa
Normal file
25
Task/Stack/Elisa/stack-2.elisa
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
component GenericStack ( Stack, ElementType );
|
||||
type Stack;
|
||||
Stack(MaxSize = integer) -> Stack;
|
||||
Empty( Stack ) -> boolean;
|
||||
Full ( Stack ) -> boolean;
|
||||
Push ( Stack, ElementType)-> nothing;
|
||||
Pull ( Stack ) -> ElementType;
|
||||
begin
|
||||
type sequence = term;
|
||||
ElementType & sequence => sequence;
|
||||
nil = null (sequence);
|
||||
|
||||
head (sequence) -> ElementType;
|
||||
head (X & Y) = ElementType:X;
|
||||
|
||||
tail (sequence) -> sequence;
|
||||
tail (X & Y) = Y;
|
||||
|
||||
Stack (Size) = Stack:[ list = nil ];
|
||||
Empty ( stack ) = (stack.list == nil);
|
||||
Full ( stack ) = false;
|
||||
Push ( stack, ElementType ) = [ stack.list:= ElementType & stack.list ];
|
||||
Pull ( stack ) = [ exception (Empty (stack), "Stack Underflow");
|
||||
Head = head(stack.list); stack.list:=tail(stack.list); Head];
|
||||
end component GenericStack;
|
||||
15
Task/Stack/Elisa/stack-3.elisa
Normal file
15
Task/Stack/Elisa/stack-3.elisa
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use GenericStack (StackofBooks, Book);
|
||||
type Book = text;
|
||||
BookStack = StackofBooks(50);
|
||||
|
||||
Push (BookStack, "Peter Pan");
|
||||
Push (BookStack, "Alice in Wonderland");
|
||||
|
||||
Pull (BookStack)?
|
||||
"Alice in Wonderland"
|
||||
|
||||
Pull (BookStack)?
|
||||
"Peter Pan"
|
||||
|
||||
Pull (BookStack)?
|
||||
***** Exception: Stack Underflow
|
||||
Loading…
Add table
Add a link
Reference in a new issue