ACSA > Tutoring > 3rd Year
Implementing an ArrayStack
Page 1 / 1
Implementing an ArrayStack
01/29/2012 1:41 pm

Junior Member


Regist.: 01/29/2012
Topics: 4
Posts: 1
OFFLINE
This is not an assignment but I think it may have be similar to a previous terms' so I am going to remove the code (although I'm sure I could find far better using Google).  I'm just trying to use the pop() method and I'm confused regarding how I am supposed to actually use its values with java.  

Michael
Quote   
01/30/2012 2:07 pm

NEWBIE


Regist.: 01/30/2012
Topics: 0
Posts: 2
OFFLINE
Do you mean what to do with the value returned from the pop() method? simple assign it too a variable eg. some int var = myStackArray.pop(); make sure you cast your variables accordingly when you do this.

or do you mean how would you implement the pop() method? to do this you will need a variable to keep track of what index of your array is the 'top' of the stack, and then when calling a pop() method you simply decrease the index variable so it points to the index of the new 'top' object in your stack as well as return the object being 'popped'.

Hope this helps?
Quote   
01/30/2012 2:13 pm

NEWBIE


Regist.: 01/30/2012
Topics: 0
Posts: 2
OFFLINE
Ps. Make sure to check if your array is empty or not before popping the stack or you will get an error!
Quote   
01/30/2012 3:14 pm

Junior Member


Regist.: 01/29/2012
Topics: 4
Posts: 1
OFFLINE
Thanks for the reply Taylor, I was part right with what I was doing but as per your first post, I wasn't casting the variable accordingly.  I think I have got it now.  Much appreciated!
Quote   
Page 1 / 1
Login with Facebook to post
Preview