a stack question

This is a discussion on a stack question within the C++ Programming forums, part of the General Programming Boards category; we had this problem given to us, and i would just like a confirmation as to who is correct on ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    4

    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. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Your solution is correct.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    > could someone please specify which is the right solution?
    http://www.programmingforums.org/for...-question.html
    http://forums.devshed.com/c-programm...on-449597.html
    Stop broadcasting your homework all over the place would be one way to avoid really ........ing off a subset of people who can help you
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked list Stack question
    By lyrick in forum C++ Programming
    Replies: 4
    Last Post: 09-23-2005, 07:23 AM
  2. Question about stack - push - pop
    By The Wiep in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2002, 12:08 PM
  3. stack implementation problem-help needed
    By sanju in forum C Programming
    Replies: 1
    Last Post: 12-10-2002, 07:29 AM
  4. HEap and stack, I'm confused
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-31-2002, 10:59 AM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 06:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21