O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

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

Commonly used APIs in a stack

The following table shows commonly used stack APIs:

API

Description

top()

This returns the top-most value in the stack, that is, the value that was added last

push<data_type>( value )

This will push the value provided to the top of the stack

pop()

This will remove the top-most value from the stack 

size()

This returns the number of values present in the stack

empty()

This returns true if the stack is empty; otherwise it returns false

 

It's time to get our hands dirty; let's write a simple program to use a stack:

#include <iostream>#include <stack>#include <iterator>#include <algorithm>using namespace std;int main ( ) {  stack<string> spoken_languages; spoken_languages.push ...

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