Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
43
Task/Stack/Phix/stack-3.phix
Normal file
43
Task/Stack/Phix/stack-3.phix
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
sequence stacks = {}
|
||||
integer freelist = 0
|
||||
|
||||
function new_stack()
|
||||
integer res = freelist
|
||||
if res!=0 then
|
||||
freelist = stacks[freelist]
|
||||
stacks[res] = {}
|
||||
else
|
||||
stacks = append(stacks,{})
|
||||
res = length(stacks)
|
||||
end if
|
||||
return res
|
||||
end function
|
||||
|
||||
procedure free_stack(integer sid)
|
||||
stacks[sid] = freelist
|
||||
freelist = sid
|
||||
end procedure
|
||||
|
||||
procedure push(integer sid, object what)
|
||||
stacks[sid] = append(stacks[sid],what)
|
||||
end procedure
|
||||
|
||||
function pop(integer sid)
|
||||
object res = stacks[sid][$]
|
||||
stacks[sid] = stacks[sid][1..$-1]
|
||||
return res
|
||||
end function
|
||||
|
||||
function empty(integer sid)
|
||||
return length(stacks[sid])=0
|
||||
end function
|
||||
|
||||
integer sid = new_stack()
|
||||
?empty(sid) -- 1
|
||||
push(sid,5)
|
||||
?empty(sid) -- 0
|
||||
push(sid,6)
|
||||
?pop(sid) -- 6
|
||||
?pop(sid) -- 5
|
||||
?empty(sid) -- 1
|
||||
free_stack(sid)
|
||||
Loading…
Add table
Add a link
Reference in a new issue