Every thing about stacks...

This is a discussion on Every thing about stacks... within the C++ Programming forums, part of the General Programming Boards category; Can you please tell me where I can find every thing about stacks....? Thank you...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Every thing about stacks...

    Can you please tell me where I can find every thing about stacks....?

    Thank you
    C++
    The best

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Can you please tell me where I can find every thing about stacks....?
    The internet, books, and experienced programmers.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Well, you might want to narrow yourself first.

    Stack is a word with several meanings.

    The first meaning of stack is a concept that dates back to the time when programmers used punch cards. The stack is a conceptual element of your computer's processor that stores data registers. When you call a function at the asm level, your current operations are suspended and said to be "put on the stack," meaning that they are shelved, but put on top, so that when your current function is done, you will go back to where you were before it started.

    Stack is also the name of an STL container with similar behavior. A good analogy for an STL stack is a tower of dimes. It is easy to put a dime on top, read the date off of the top dime, or remove the top dime, but it would be difficult to read the date of the bottom dime, or insert a dime in the middle.

  4. #4
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Also Prelude, I hate to break it to you, but this is the internet, and you are an experienced programmer.


  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Also Prelude, I hate to break it to you, but this is the internet,
    >and you are an experienced programmer.
    Oh! So that's why people keep asking me questions. Whew, it's nice to have that mystery solved.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Bout time. Now quit jabbering and get back to work.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Now quit jabbering and get back to work.
    What is a stack? A stack is a data structure that is well suited for LIFO type situations where the last item to enter the stack is the first to leave. A good example would be scope levels in a C++ program:
    Code:
    // This is our program
    #include <iostream>
    using std::cout;
    
    void funcOne ( void )
    {
      cout<<"push funcOne\npop funcOne\n";
    }
    
    int main ( void )
    {
      cout<<"push main\n";
      for ( int x = 0; x < 3; x++ ) {
        cout<<"push for\n";
        funcOne();
        cout<<"pop for\n";
      }
      cout<<"pop main\n";
      return 0;
    }
    Upon entering main you can consider main to be pushed onto the stack, so it's the only item in our hypothetical example. When the loop is entered, it too is pushed onto the stack because it's a block and has it's own scope. Now you have main at the bottom of the stack and for on top of main. When funcOne is called, it too is pushed onto the stack on top of for. Scope is now in funcOne.

    When funcOne returns, it is popped off of the stack because it is no longer needed and the scope returns to for. Just to simplify things, I've set it up so that for is popped when each iteration is finished and pushed when an interation starts (my example, my rules, no?). This process occurs three times, for is pushed, funcOne is pushed then popped, and for is popped. When the third iteration completes and the loop is finished, main returns and is popped from the stack. The program is finished. The life of the stack looks like this:
    Code:
                      f1                      f1                      f1
                for   for   for         for   for   for         for   for   for
    ----  main  main  main  main  main  main  main  main  main  main  main  main  main  ----
    For further illustration please run the program and/or ask for clarification on any point where I was hazy.

    -Prelude
    My best code is written with the delete key.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Thumbs up You Guys are Great ....

    Thank you Guys ..........
    You are Great...
    Look if I find something I will write it here....
    C++
    The best

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please Help Me With This Code Of Implementing Stacks
    By raghu_equinox in forum C Programming
    Replies: 3
    Last Post: 10-19-2006, 08:22 AM
  2. A very strange thing
    By gustavosserra in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2003, 01:43 PM
  3. most challenging thing to program
    By volk in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 03-28-2003, 03:56 PM
  4. question about stacks (and vectors too for that matter)
    By Silvercord in forum C++ Programming
    Replies: 3
    Last Post: 03-19-2003, 12:26 PM

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