├── LB-DSA-Programs ├── 04_main.cpp ├── 00_Hashing.exe ├── 05_solid_rectangle.cpp ├── 16_solid_square.cpp ├── 04_main2.cpp ├── 05_half_pyramid.cpp ├── 05_inverted_half_pyramid.cpp ├── 05_inverted_numeric_half_pyramid.cpp ├── 05_numeric_half_pyramid.cpp ├── 21_Numeric_half_pyramid.cpp ├── 00_pairs.cpp ├── 18_hollow_inverted_half_pyramid.cpp ├── 20_solid_full_inverted_pyramid.cpp ├── 05_hollow_rectangle.cpp ├── 20_solid_full_pyramid_with_space.cpp ├── 05_hollow_rectangle2.cpp ├── 17_hollow_square.cpp ├── 20_numeric_palindrome.cpp ├── 05_solid_full_pyramid.cpp ├── 20_alphabetic_palindrome.cpp ├── 21_Numeric_full_pyramid.cpp ├── 00_Hashing.cpp ├── 20_fancy_pattern.cpp ├── 20_solid_diamond.cpp ├── 19_hollow_full_pyramid.cpp ├── 20_flipped_solid_pyramid.cpp ├── 21_Numeric_hollow_pyramid.cpp ├── 20_hollow_diamond.cpp ├── 00_vectors.cpp └── 00_STL_data_structures_part_A.cpp ├── README.md └── LICENSE /LB-DSA-Programs/04_main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | std::cout << "Hello World!\n"; 5 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/00_Hashing.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aniket-2003-das/LB-DSA-Programs/HEAD/LB-DSA-Programs/00_Hashing.exe -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LB-DSA-Programs 2 | 3 | Contains my beginner level dsa Programs on -: 4 | c++; 5 | loops; 6 | pattern Printing; 7 | STL Library; 8 | hashing; 9 | sorting; 10 | etc; 11 | -------------------------------------------------------------------------------- /LB-DSA-Programs/05_solid_rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | for (int row = 0; row < 3; row = row + 1){ 6 | for (int col = 0; col < 5; col = col + 1){ 7 | cout << "* "; 8 | } 9 | cout << endl; 10 | } 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/16_solid_square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin >> n ; 7 | for (int i = 0; i < n; i++) 8 | { 9 | for (int j = 0; j < n; j++) 10 | { 11 | cout << "*"; 12 | } 13 | cout << endl; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /LB-DSA-Programs/04_main2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | // std::cout << "hello world\n" << std::endl; 6 | // cout << "hello world\n" << endl; 7 | // cout << endl; 8 | 9 | cout << "enter a number\n" << endl; 10 | int a; 11 | 12 | cin >> a; 13 | cout << "you entered\n" << a; 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/05_half_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | 8 | for (int row = 0; row < n; row++) 9 | { 10 | for (int col = 0; col < row + 1 ; col = col + 1) { 11 | cout << "* "; 12 | } 13 | cout << endl; 14 | } 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/05_inverted_half_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | 8 | for (int row = 0; row < n; row++) 9 | { 10 | for (int col = 0; col < n - row ; col = col + 1) { 11 | cout << "* "; 12 | } 13 | cout << endl; 14 | } 15 | return 0; 16 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/05_inverted_numeric_half_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | 8 | for (int row = 0; row < n; row++) 9 | { 10 | for (int col = 0; col < n - row ; col = col + 1) { 11 | cout << col + 1; 12 | } 13 | cout << endl; 14 | } 15 | return 0; 16 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/05_numeric_half_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | 8 | for (int row = 0; row < n; row++) 9 | { 10 | for (int col = 0; col < row + 1 ; col = col + 1) { 11 | cout << col + 1; 12 | } 13 | cout << endl; 14 | } 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/21_Numeric_half_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | int k = 0 ; 8 | 9 | for (int row = 0; row < n; row = row + 1) 10 | { 11 | for (int col = 0; col < row + 1; col = col + 1) 12 | { 13 | cout << row+col+1; 14 | } 15 | cout << endl; 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/00_pairs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void explainPair(){ 5 | pair p = {1, 3}; 6 | cout << p.first << " " << p.second << endl; 7 | 8 | pair> a = {1, {1, 3}}; 9 | cout << a.first << " and " << a.second.first << " " << a.second.second << endl; 10 | 11 | pair arr[] = {{1,2}, {2,5}, {4,3}}; 12 | cout << arr[1].second; 13 | 14 | } 15 | 16 | int main (){ 17 | explainPair(); 18 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/18_hollow_inverted_half_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | for (int i = 0; i < n; i++) 8 | { 9 | for (int j = 0; j < n; j++) 10 | { 11 | if (i == 0 || j == 0 || j == n - i -1){ 12 | cout << "* "; 13 | } 14 | else 15 | { 16 | cout << " "; 17 | } 18 | } 19 | cout << endl; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/20_solid_full_inverted_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | int k = 0 ; 8 | 9 | for (int row = 0; row < n; row = row + 1) 10 | { 11 | for (int col = 0; col < row ; col = col + 1) 12 | { 13 | cout << " "; 14 | } 15 | for (int col = 0; col < (n-row); col = col + 1) 16 | { 17 | 18 | cout << "* "; 19 | } 20 | cout << endl; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LB-DSA-Programs/05_hollow_rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | for (int row = 0; row < 3; row = row + 1) 7 | { 8 | if (row == 0 || row == 2) 9 | { 10 | for ( int col = 0; col < 5; col++) 11 | { 12 | cout << "*"; 13 | } 14 | } 15 | else 16 | { 17 | cout << "*"; 18 | for (int i = 0; i < 3; i++) 19 | { 20 | cout << " "; 21 | } 22 | cout << "* "; 23 | } 24 | cout << endl; 25 | } 26 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/20_solid_full_pyramid_with_space.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | int k = 0 ; 8 | 9 | for (int row = 0; row < n; row = row + 1) 10 | { 11 | for (int col = 0; col < (n-row-1); col = col + 1) 12 | { 13 | cout << " "; 14 | } 15 | for (int col = 0; col < (row+1); col = col + 1) 16 | { 17 | 18 | cout << "* "; 19 | } 20 | cout << endl; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/05_hollow_rectangle2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | for (int row = 0; row < 4; row = row + 1) 7 | { 8 | if (row == 0 || row == 3) 9 | { 10 | for ( int col = 0; col < 5; col++) 11 | { 12 | cout << "*"; 13 | } 14 | } 15 | else 16 | { 17 | cout << "*"; 18 | for (int i = 0; i < 3; i++) 19 | { 20 | cout << " "; 21 | } 22 | cout << "* "; 23 | } 24 | cout << endl; 25 | } 26 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/17_hollow_square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | for (int i = 0; i < n; i++) 9 | { 10 | for (int j = 0; j < n; j++) 11 | { 12 | if (i==0 || i == (n-1) || j==0 || j == (n-1)) 13 | { 14 | cout << "*"; 15 | } 16 | else 17 | { 18 | cout << " "; 19 | } 20 | 21 | 22 | } 23 | cout << endl; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/20_numeric_palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | 8 | for (int row = 0; row < n; row++) { 9 | 10 | int col; 11 | // straight counting. 12 | for (col = 0; col < row + 1 ; col = col + 1) { 13 | cout << (col+1); 14 | } 15 | col = col - 1; 16 | 17 | // reverse counting. 18 | for (; col >=1; col = col - 1) { 19 | cout << col; 20 | } 21 | cout << endl; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/05_solid_full_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | int k = 0 ; 8 | 9 | for (int i = 0; i < n; i++) 10 | { 11 | int k = 0; 12 | for (int j = 0; j < (2*n-1); j++) 13 | { 14 | if (j < n-i-1){ 15 | cout << " "; 16 | } 17 | else if (k < ((2*i)+1)) 18 | { 19 | cout << "*"; 20 | k++; 21 | } 22 | else 23 | { 24 | cout << " "; 25 | } 26 | } 27 | cout << endl; 28 | } 29 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/20_alphabetic_palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | 8 | for (int row = 0; row < n; row++) { 9 | 10 | int col; 11 | // straight counting. 12 | for (col = 0; col < row + 1 ; col = col + 1) { 13 | int ans = col + 1; 14 | char ch = ans + 'A' -1; 15 | cout << ch; 16 | } 17 | // reverse counting. 18 | for (int col = row; col >=1; col = col - 1) { 19 | int ans = col; 20 | char ch = ans + 'A' -1; 21 | cout << ch; 22 | } 23 | cout << endl; 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/21_Numeric_full_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | int k = 0 ; 8 | 9 | for (int row = 0; row < n; row = row + 1) 10 | { 11 | for (int col = 0; col < (n-row-1); col = col + 1) 12 | { 13 | cout << " "; 14 | } 15 | for (int col = 0; col < (row+1); col = col + 1) 16 | { 17 | 18 | cout << (row+col+1); 19 | } 20 | int start = 2*row; 21 | for (int col = 0; col < row; col = col + 1) 22 | { 23 | cout << start; 24 | start = start - 1; 25 | } 26 | cout << endl; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/00_Hashing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int hash[1000000] = {0}; //Possible till 10^6 and 10^7 for bool for array declared globally. 5 | int main(){ 6 | 7 | int n; 8 | cin >> n; 9 | int arr[n]; 10 | for (int i =0; i> arr[i]; 12 | } 13 | 14 | // precomutation (to check 1, 2, 4, 5, 12) in array 15 | int hash[1000000] = {0}; //Possible till 10^6 and 10^7 for bool for array declared in int main. 16 | for (int i =0; i> q; 22 | while(q--){ 23 | int number; 24 | cin >> number; 25 | // fetching 26 | cout << hash[number] << endl; 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/20_fancy_pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | 8 | for (int row = 0; row < n; row++) 9 | { 10 | for (int col = 0; col < row + 1 ; col = col + 1) { 11 | cout << (row+1); 12 | if (row!=col) 13 | { 14 | cout << "*"; 15 | } 16 | 17 | } 18 | cout << endl; 19 | } 20 | for (int row = 0; row < n; row++) 21 | { 22 | for (int col = 0; col < n-row; col = col + 1) { 23 | cout << (n-row); 24 | if (col!=n-row-1) 25 | { 26 | cout << "*"; 27 | } 28 | } 29 | cout << endl; 30 | } 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/20_solid_diamond.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | 8 | for (int row = 0; row < n; row = row + 1) 9 | { 10 | for (int col = 0; col < (n-row-1); col = col + 1) 11 | { 12 | cout << " "; 13 | } 14 | for (int col = 0; col < (row+1); col = col + 1) 15 | { 16 | 17 | cout << "* "; 18 | } 19 | cout << endl; 20 | } 21 | for (int row = 0; row < n; row = row + 1) 22 | { 23 | for (int col = 0; col < row ; col = col + 1) 24 | { 25 | cout << " "; 26 | } 27 | for (int col = 0; col < (n-row); col = col + 1) 28 | { 29 | 30 | cout << "* "; 31 | } 32 | cout << endl; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/19_hollow_full_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | int k = 0 ; 8 | 9 | for (int i = 0; i < n; i++) 10 | { 11 | int k = 0; 12 | for (int j = 0; j < (2*n-1); j++) 13 | { 14 | if (j < n-i-1) 15 | { 16 | cout << " "; 17 | } 18 | else if (k < ((2*i)+1)) 19 | { 20 | if (k==0 || k == 2*i || i == n-1) 21 | { 22 | cout << "* "; 23 | } 24 | else 25 | { 26 | cout << " "; 27 | } 28 | k++; 29 | } 30 | else 31 | { 32 | cout << " "; 33 | } 34 | } 35 | cout << endl; 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Aniket Das 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LB-DSA-Programs/20_flipped_solid_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | 8 | for (int row = 0; row < n; row = row + 1) 9 | { 10 | for (int col = 0; col < (n-row); col = col + 1) 11 | { 12 | cout << "*"; 13 | } 14 | for (int col = 0; col < (2*row+1); col = col + 1) 15 | { 16 | 17 | cout << " "; 18 | } 19 | for (int col = 0; col < (n-row); col = col + 1) 20 | { 21 | cout << "*"; 22 | } 23 | cout << endl; 24 | } 25 | for (int row = 0; row < n; row = row + 1) 26 | { 27 | for (int col = 0; col < row + 1 ; col = col + 1) 28 | { 29 | cout << "*"; 30 | } 31 | for (int col = 0; col < (2*n-2*row-1); col = col + 1) 32 | { 33 | 34 | cout << " "; 35 | } 36 | for (int col = 0; col < (row+1); col = col + 1) 37 | { 38 | cout << "*"; 39 | } 40 | cout << endl; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/21_Numeric_hollow_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | cin >> n; 7 | 8 | for (int row = 0; row < n; row++) { 9 | for (int col = 0; col < (n -row-1); col++) { 10 | cout << " "; 11 | } 12 | int start = 1; 13 | for (int col = 0; col < (2 *row+1); col++) { 14 | // First and last row or first and last column in the row 15 | if (row==0||row==n-1) { 16 | if(col%2==0) { 17 | cout << start; 18 | start++; 19 | } 20 | else { 21 | cout << " "; 22 | } 23 | } 24 | else { 25 | if (col==0){ 26 | cout << 1; 27 | } 28 | else if (col==2*row) 29 | { 30 | cout<< row+1; 31 | } 32 | else{ 33 | cout << " "; 34 | } 35 | 36 | } 37 | } 38 | 39 | cout << endl; 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /LB-DSA-Programs/20_hollow_diamond.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n ; 6 | cin >> n ; 7 | 8 | for (int row = 0; row < n; row = row + 1) 9 | { 10 | for (int col = 0; col < (n-row-1); col = col + 1) 11 | { 12 | cout << " "; 13 | } 14 | for (int col = 0; col < (2*row+1); col = col + 1) 15 | { 16 | if (col==0 || col==2*row) 17 | { 18 | cout << "*"; 19 | } 20 | else 21 | { 22 | cout << " "; 23 | } 24 | } 25 | cout << endl; 26 | } 27 | for (int row = 0; row < n; row = row + 1) 28 | { 29 | for (int col = 0; col < row; col = col + 1) 30 | { 31 | cout << " "; 32 | } 33 | for (int col = 0; col < (2*n - 2*row - 1); col = col + 1) 34 | { 35 | if (col==0 || col==2*n - 2*row - 2) 36 | { 37 | cout << "*"; 38 | } 39 | else 40 | { 41 | cout << " "; 42 | } 43 | } 44 | cout << endl; 45 | } 46 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/00_vectors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void explainvector() { 5 | vector v; 6 | 7 | v.push_back(1); 8 | v.emplace_back(2); 9 | 10 | vector> vec; 11 | vec.push_back({1,2}); 12 | v.emplace_back(2,3); 13 | 14 | vector v(5,100); 15 | vector v(5); 16 | 17 | vector v1(2,50); 18 | vector v2(v1); 19 | 20 | 21 | 22 | 23 | // Accessing elements in a vector. 24 | vector::iterator it1 = v.begin(); 25 | vector::iterator it2 = v.end(); 26 | // vector::iterator it3 = v.rend(); 27 | // vector::iterator it4 = v.rbegin(); 28 | 29 | 30 | vector::iterator it1 = v.begin(); 31 | it1++; 32 | cout << *(it1) << " "; 33 | 34 | it1 = it1 + 2; 35 | cout << *(it1) << " "; 36 | 37 | cout << v[0] << " " << v[1]; 38 | cout << v.at(0); 39 | cout << v.back(); 40 | 41 | for(vector::iterator it = v.begin(); it != v.end(); it++) { 42 | cout << *(it) << " "; 43 | } 44 | 45 | for(auto it = v.begin(); it != v.end(); it++) { 46 | cout << *(it) << " "; 47 | } 48 | 49 | for(auto it : v){ 50 | cout << it < v(2,100); 63 | v.insert(v.begin(), 300); 64 | 65 | v.insert(v.begin() + 1, 2, 10); 66 | 67 | vector copy(2,50); 68 | v.insert(v.begin(), copy.begin(), copy.end()); 69 | 70 | 71 | 72 | 73 | 74 | // Vector Properties-: 75 | v.size(); 76 | v.pop_back(); 77 | 78 | v1.swap(v2); 79 | v.clear(); 80 | cout << v.empty(); 81 | 82 | } -------------------------------------------------------------------------------- /LB-DSA-Programs/00_STL_data_structures_part_A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void explainList() { 5 | list ls; 6 | 7 | ls.push_back(2); 8 | ls.emplace_back(4); 9 | 10 | ls.push_front(5); 11 | 12 | ls.emplace_front(); 13 | 14 | // rest functions are same as vector functions. 15 | // begin, end, rbegin, rend, clear, insert, size, swap. 16 | } 17 | 18 | 19 | void explainDeque() { 20 | 21 | dequedq; 22 | dq.push_back(1); 23 | dq.emplace_back(2); 24 | dq.pop_front(); 25 | dq.emplace_front(3); 26 | 27 | dq.pop_back(); 28 | dq.pop_front(); 29 | 30 | dq.back(); 31 | dq.front(); 32 | 33 | // rest functions are same as vector functions. 34 | // begin, end, rbegin, rend, clear, insert, size, swap. 35 | 36 | } 37 | 38 | 39 | void explainStack() { 40 | stack st; 41 | st.push(1); 42 | st.push(2); 43 | st.push(3); 44 | st.push(3); 45 | st.emplace(5); 46 | 47 | cout << st.top(); 48 | 49 | st.pop(); 50 | 51 | cout << st.top(); 52 | 53 | cout << st.size(); 54 | 55 | cout << st.empty(); 56 | 57 | stack st1, st2; 58 | st1.swap(st2); 59 | 60 | } 61 | 62 | 63 | void explainQueue() { 64 | queue q; 65 | q.push(1); 66 | q.push(2); 67 | q.emplace(4); 68 | 69 | q.back() += 5; 70 | 71 | cout << q.back(); 72 | 73 | cout << q.front(); 74 | 75 | q.pop(); 76 | 77 | cout << q.front(); 78 | 79 | 80 | // size swap empty same as stack. 81 | 82 | } 83 | 84 | 85 | void explainPriority_queue() { 86 | priority_queue pq; 87 | 88 | pq.push(5); 89 | pq.push(2); 90 | pq.push(8); 91 | pq.emplace(10); 92 | 93 | cout << pq.top(); 94 | 95 | // size swap empty functiojn same as others. 96 | 97 | // Minimum Heap 98 | priority_queue, greater> pq; 99 | pq.push(5); 100 | pq.push(2); 101 | pq.push(8); 102 | pq.emplace(10); 103 | 104 | cout<< pq.top(); 105 | 106 | } --------------------------------------------------------------------------------