Nov 13, 2018
Stack in C++ STL
Last updated
Stack in C++ STL
Last updated
The functions associated with stack are:
– Returns whether the stack is empty – Time Complexity : O(1)
– Returns the size of the stack – Time Complexity : O(1)
– Returns a reference to the top most element of the stack – Time Complexity : O(1)
– Adds the element g
at the top of the stack – Time Complexity : O(1)
– Deletes the top most element of the stack – Time Complexity : O(1)
Output:
Queues are a type of container adaptors which operate in a first in first out (FIFO) type of arrangement. Elements are inserted at the back (end) and are deleted from the front.
The functions supported by queue are :
empty()
– Returns whether the queue is empty
size()
– Returns the size of the queue
front()
– Returns a reference to the first element of the queue
back()
– Returns a reference to the last element of the queue
push(g)
– Adds the element g
at the end of the queue
pop()
– Deletes the first element of the queue
Output: