Get Started. It's Free
or sign up with your email address
Stacks by Mind Map: Stacks

1. methods

1.1. 1- nameOfStack.size(); to return the size of stack. time complexity: O(1).

1.2. 2- nameOfStack.push(variable); to push the variable to stack. time complexity: O(1).

1.3. 3- nameOfStack.pop(); to get the last value in stack. time complexity: O(1).

1.4. 4- first.swap(second); to swap variables between first and second stack. time complexity: O(1).

1.5. 5- nameOfStack.top(); to access next element in the stack. time complexity: O(1).

1.6. 6- nameOfStack.empty(); test the stack if its empty return true if not return false. time complexity: O(1).

1.7. 3- nameOfStack.pop(); to get the last value in stack.

2. Definition

2.1. Stacks are type of data structures that holds the same type of variable in list

3. functions

3.1. To create a stack you should included first then defined. ex/ stack<(type)>name of stack;

3.1.1. #include <iostream>

4. Deference

4.1. the deference between stacks and other data structures type like queue is the way to insert an element and get the element.

4.1.1. Last in first out. It means the last element pushed in to the stack the first element out.

5. #include <iostream> #include<stack> //include stack using namespace std; int main(){ stack<int>t; //define stack t.push(5); //push 5 to stack return 0; }