vik-y
5/28/2017 - 3:36 AM

Simple Examples of stack and queue in C++ Standard Library

Simple Examples of stack and queue in C++ Standard Library

// cplusplus reference can be useful
// http://www.cplusplus.com/reference/queue/queue/
#include <iostream>
#include <queue>
#include <stack>

int main(){
  std::stack<int> s; // Define a stack which stores integers
  std::queue<int> q; // Define a queue which stores integers
  s.push(5); //Add an element to stack
  q.push(5); //Add an element to queue
  s.top(); // Get the element at the top of the the stack
  q.front(); // Get the element at front of the queue 
  s.pop(); // Delete the top element in stack
  q.pop(); // Delete the element in front of the queue
}