Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   a stack question (http://www.programmingforums.org/showthread.php?t=13275)

JJH35 Jun 3rd, 2007 9:56 PM

a stack question
 
we had this problem given to us, and i would just like a confirmation as to who is correct on the answer

the stacks S and T are initially empty and we need to say what they would "look like" after these operations

S.push(1)
S.push(2)
T.push(3)
T.push(4)
S.pop
T.GetStackTop(StackTop)
S.push(StackTop)
S.push(5)
T.pop(StackTop)
T.push(6)

I came up with S containing (from bottom to top) 1,4,5
and T containing 3,6

but a friend had only 6 left in T

could someone please specify which is the right solution?

DaWei Jun 4th, 2007 12:13 AM

You'll have to explain what GetStackTop does in terms of its effect on the contents. If it merely returns the value, without removing it (which seems likely), then just make a table. The operation, T.pop(StackTop), seems ridiculous. How can you specify some parameter to pop? One pops the top. If it's specifiying a destination in which to place the popped value, it's useless, as you don't subsequently use it.

In other words, a question without the necessary supportive information isn't likely to result in a good answer, except by accident.

ReggaetonKing Jun 4th, 2007 1:03 AM

Agree with DaWei on this. Provide more information and then you'll get something good! I do not know what StackTop is.

pegasus001 Jun 4th, 2007 7:08 AM

Are we really talking about stacks here???


All times are GMT -5. The time now is 2:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC