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

1. Definition

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

2. functions

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

2.1.1. #include <iostream>

3. methods

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

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

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

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

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

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

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

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; }