![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 6
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Sexy Programmer
|
Agree with DaWei on this. Provide more information and then you'll get something good! I do not know what StackTop is.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 215
Rep Power: 3
![]() |
Are we really talking about stacks here???
__________________
You never test the depth of a river with both feet. The believer is happy. The doubter is wise. Free speech carries with it some freedom to listen. The next generation will always surpass the previous one. It`s one of the never ending cycles of life. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Combining languages | titaniumdecoy | Other Programming Languages | 12 | Jul 13th, 2006 3:03 PM |
| stack question | bl00dninja | C++ | 9 | May 8th, 2006 8:54 PM |
| Assembly tutorial, part one. | Mad_guy | Software Design and Algorithms | 21 | Apr 15th, 2006 8:02 PM |
| When to use the new keyword in C++? | titaniumdecoy | C++ | 28 | Mar 16th, 2006 1:36 PM |
| A noob to Assembly | CodeJunkie | Assembly | 12 | Jan 25th, 2006 3:06 PM |