Skip to Content
Mastering C++ Programming
book

Mastering C++ Programming

by Jeganathan Swaminathan
September 2017
Beginner to intermediate
384 pages
8h 4m
English
Packt Publishing
Content preview from Mastering C++ Programming

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Multi-Paradigm Programming with Modern C++

Multi-Paradigm Programming with Modern C++

Georgy Pashkov

Publisher Resources

ISBN: 9781786461629Supplemental Content