Skip to content

Instantly share code, notes, and snippets.

@antsmartian
Created February 5, 2012 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antsmartian/1743346 to your computer and use it in GitHub Desktop.
Save antsmartian/1743346 to your computer and use it in GitHub Desktop.
Stack on Groovy ;)
input = args[0] as Integer
top = -1
stack = new long[input]
def push(long j)
{
stack.putAt(++top,j)
}
def pop()
{
stack.getAt(top--)
}
boolean isEmpty()
{
top == -1
}
boolean isFull()
{
top == input -1
}
println '''
pushing the elements into the stack
***********************************
'''
(3..9).each { elements ->
if(isFull())
println "Sorry the stack is full"
else
{
push elements
println "successfull added the element, $elements into the stack"
}
}
println '''
Now poping the elements out
*****************************
'''
(3..9).each {
if(!isEmpty())
pop()
else
println "sorry stack is alreay empty"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment