Stack

This is a discussion on Stack within the C Programming forums, part of the General Programming Boards category; How can I use a stack to reverse the order of a string. If I have "abcde" I want to ...

  1. #1
    Max
    Max is offline
    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,386
    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, 01:56 AM
  3. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 09:12 PM
  4. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 05:27 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM

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