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
23
Task/Stack/Phix/stack-1.phix
Normal file
23
Task/Stack/Phix/stack-1.phix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
sequence stack = {}
|
||||
|
||||
procedure push(object what)
|
||||
stack = append(stack,what)
|
||||
end procedure
|
||||
|
||||
function pop()
|
||||
object what = stack[$]
|
||||
stack = stack[1..$-1]
|
||||
return what
|
||||
end function
|
||||
|
||||
function empty()
|
||||
return length(stack)=0
|
||||
end function
|
||||
|
||||
?empty() -- 1
|
||||
push(5)
|
||||
?empty() -- 0
|
||||
push(6)
|
||||
?pop() -- 6
|
||||
?pop() -- 5
|
||||
?empty() -- 1
|
||||
26
Task/Stack/Phix/stack-2.phix
Normal file
26
Task/Stack/Phix/stack-2.phix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
function push(sequence stack, object what)
|
||||
stack = append(stack,what)
|
||||
return stack
|
||||
end function
|
||||
|
||||
function pop(sequence stack)
|
||||
object what = stack[$]
|
||||
stack = stack[1..$-1]
|
||||
return {stack,what}
|
||||
end function
|
||||
|
||||
function empty(sequence stack)
|
||||
return length(stack)=0
|
||||
end function
|
||||
|
||||
sequence stack = {}
|
||||
?empty(stack) -- 1
|
||||
stack = push(stack,5)
|
||||
?empty(stack) -- 0
|
||||
stack = push(stack,6)
|
||||
integer top
|
||||
{stack,top} = pop(stack)
|
||||
?top -- 6
|
||||
{stack,top} = pop(stack)
|
||||
?top -- 5
|
||||
?empty(stack) -- 1
|
||||
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