Skip to content

Instantly share code, notes, and snippets.

@vik-y
Last active May 28, 2017 03:39
Show Gist options
  • Save vik-y/8ddea4dcb44d3395d8c63f859c32a20d to your computer and use it in GitHub Desktop.
Save vik-y/8ddea4dcb44d3395d8c63f859c32a20d to your computer and use it in GitHub Desktop.
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment