Thread: a stack question

  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,318
    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
    39,660
    > 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.

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, 06: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, 05:36 PM