RosettaCodeData/Task/Queue-Usage/AppleScript/queue-usage.applescript

30 lines
667 B
AppleScript
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
on push(StackRef, value)
2014-01-17 05:32:22 +00:00
set StackRef's contents to {value} & StackRef's contents
return StackRef
2013-04-10 23:57:08 -07:00
end push
on pop(StackRef)
2014-01-17 05:32:22 +00:00
set R to missing value
if StackRef's contents {} then
set R to StackRef's contents's item 1
set StackRef's contents to {} & rest of StackRef's contents
end if
return R
2013-04-10 23:57:08 -07:00
end pop
on isStackEmpty(StackRef)
2014-01-17 05:32:22 +00:00
if StackRef's contents = {} then return true
return false
2013-04-10 23:57:08 -07:00
end isStackEmpty
set theStack to {}
repeat with i from 1 to 5
2014-01-17 05:32:22 +00:00
push(a reference to theStack, i)
log result
2013-04-10 23:57:08 -07:00
end repeat
repeat until isStackEmpty(theStack) = true
2014-01-17 05:32:22 +00:00
pop(a reference to theStack)
log result
2013-04-10 23:57:08 -07:00
end repeat