Thread: Stack

  1. #1
    Registered User Max's Avatar
    Join Date
    Jul 2002
    Posts
    110

    Stack

    How can I use a stack to reverse the order of a string.

    If I have "abcde" I want to print the reverse "edcba". But I want a stack program to do the reverse action.

    I need some logical guidance. I do have a working stack program.

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    A stack works according to the LIFO (last in - first out) principe.

    Assume data is: abcde. If you push 'a' first on the stack, than the stack looks like:

    e - top
    d
    c
    b
    a - bottom

    Now you pop 'e' first from the stack. So popping all data from the stack results in:

    edcba

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  2. infix evaluation using stack
    By lewissi in forum C++ Programming
    Replies: 0
    Last Post: 11-03-2005, 02:56 AM
  3. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  4. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 06:27 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM