Created
February 5, 2012 06:00
-
-
Save antsmartian/1743346 to your computer and use it in GitHub Desktop.
Stack on Groovy ;)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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