stack

This is a discussion on stack within the C++ Programming forums, part of the General Programming Boards category; in a nutshell.. what does the stack function do? thanks raz...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    19

    Talking stack

    in a nutshell..

    what does the stack function do?

    thanks

    raz

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    push and pop

  3. #3
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    think of it as a stack of plates. each time you add a plate it goes on top (push onto the stack). then when you want to use a plate you take the top most one (pop from stack). You always have access to the last thing you put onto the stack. (you can get to everything else too but that defeats the purpose)

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    1

    Stack is actually an ADT, not a function.

    Also, a stack is an abstract data type (ADT), not a function. This means that it is an class which contains a place to hold the data, either an array or a linked list, and the two member functions explained above, namely push and pop. It is also considered LIFO or Last In First Out, which goes right along with the stack of plates example.

    An example of a use for a stack is when a computer translates an expression in infix notation (3+2) to postfix notation (32+), it uses a stack as part of that conversion. Actually, it uses the stack to evaluate the newly created postfix expression as well.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well, the word "stack" (like heap) has two different meanings, although they are similar.

    *A* stack is an abstract data type which is essentially a first in, last out data structure, which behaves as mentioned in previous posts.

    *The* stack operates similarly, and is used for storage of local variables, as well as parameters and return values to functions.

    Any variable or object you create is created on the stack. Any memory allocated by malloc() or new is allocated on the heap (which actually is nothing like *a* heap which is another ADT).

    When using the term "stack" or "heap" be sure to make the context tell the reader which meaning you're talking about, as, especially for a stack vs. the stack, they are easily confused.

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