all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
41
Task/Stack/Seed7/stack.seed7
Normal file
41
Task/Stack/Seed7/stack.seed7
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const func type: stack (in type: baseType) is func
|
||||
result
|
||||
var type: stackType is void;
|
||||
begin
|
||||
stackType := array baseType;
|
||||
|
||||
const proc: push (inout stackType: aStack, in baseType: top) is func
|
||||
begin
|
||||
aStack := [] (top) & aStack;
|
||||
end func;
|
||||
|
||||
const func baseType: pop (inout stackType: aStack) is func
|
||||
result
|
||||
var baseType: top is baseType.value;
|
||||
begin
|
||||
if length(aStack) = 0 then
|
||||
raise RANGE_ERROR;
|
||||
else
|
||||
top := aStack[1];
|
||||
aStack := aStack[2 ..];
|
||||
end if;
|
||||
end func;
|
||||
|
||||
const func boolean: empty (in stackType: aStack) is
|
||||
return length(aStack) = 0;
|
||||
end func;
|
||||
|
||||
const type: intStack is stack(integer);
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var intStack: s is intStack.value;
|
||||
begin
|
||||
push(s, 10);
|
||||
push(s, 20);
|
||||
writeln(pop(s) = 20);
|
||||
writeln(pop(s) = 10);
|
||||
writeln(empty(s));
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue