O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Stack

A stack is a vector that you can address only from one end, known as the top. You usually create it without data, push elements onto the stack, and then pop them off again. This is so similar to the vector that the following code should give all the necessary explanation:

stack<char> my_Lifo;
my_Lifo.push( 'a' );
my_Lifo.push( 'b' );
my_Lifo.push( 'c' );

char cLook = my_Lifo.top(); // sneak a preview into cLook

char cTake = my_Lifo.pop(); // pop the top off the stack

You can also use the empty and size operators to determine whether the stack contains data, and how much. You do not have any other operators for clearing the stack or interacting with it in any other way.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required