[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppStack

(C++) std::stack

STL container class for storing values of any data type. Can be found in the header file stack.

It can increase in size at run-time at one side (using push) and decrease is size (using pop). Only the top of the stack can be read (using top). Therefore, the std::stack has a LIFO ('last in, first out') structure.

  1. include <iostream>
  2. include <stack>
int main() { std::stack<int> s; s.push(0); //First in s.push(1); s.push(2); //Last in std::cout << s.top() << std::endl; //Get the latest entry s.pop(); std::cout << s.top() << std::endl; s.pop(); std::cout << s.top() << std::endl; s.pop(); }


resulting in the output:

2
1
0


A std::stack can be seen as a stripped-down std::vector/std::deque with only one side read/write-able.

Code links

Links



last edited (November 18, 2006) by bilderbikkel, Number of views: 3483, Current Rev: 6 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.