├── Containers ├── SequenceContainers │ ├── vector │ └── vector.cpp ├── stack └── stack.cpp ├── PriorityQueue ├── minHeapPriorityQueue ├── minHeapPriorityQueue.cpp ├── priorityQueue └── priorityQueue.cpp └── README.md /Containers/SequenceContainers/vector: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasikahmed/StandardTemplateLibrary-CPP/f38b6e0319398b769471de900c2f8041ba8cd096/Containers/SequenceContainers/vector -------------------------------------------------------------------------------- /Containers/SequenceContainers/vector.cpp: -------------------------------------------------------------------------------- 1 | // Vectors are dynamic arrays 2 | // can change size during runtime 3 | // contiguous storage location 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | void printVector(vector v) { 10 | for(auto i=v.begin(); i!=v.end(); i++) { 11 | cout<< *i<< " "; 12 | } 13 | cout<< endl; 14 | } 15 | 16 | int main() { 17 | 18 | vector v; 19 | for(int i=10; i<=100; i+=10) { 20 | v.push_back(i); // push element in vector 21 | } 22 | 23 | // iterators 24 | 25 | // auto b = v.begin(); 26 | // cout<< *b<< endl; 27 | // auto e = v.end(); 28 | // cout<< *e<< endl; 29 | // for(auto i=b; i!=e; i++) { 30 | // cout<< *i<< endl; 31 | // } 32 | cout<< "Vector elements: "; 33 | printVector(v); 34 | 35 | // capacity 36 | 37 | if(v.empty()) 38 | cout<< "Vector is empty"<< endl; 39 | else 40 | cout<< "Vector is not empty"<< endl; 41 | 42 | cout<< "Vector size: "<< v.size()<< endl; 43 | cout<< "Max size: "<< v.max_size()<< endl; 44 | cout<< "Capacity: "<< v.capacity()<< endl; 45 | 46 | v.resize(40); // resize vector size to 40 47 | cout<< "Resized vector(40): "; 48 | printVector(v); 49 | cout<< "Vector size: "<< v.size()<< endl; 50 | cout<< "Capacity: "<< v.capacity()<< endl; 51 | 52 | v.resize(5); // resize vector size to 5 53 | cout<< "Resized vector(5): "; 54 | printVector(v); 55 | cout<< "Vector size: "<< v.size()<< endl; 56 | cout<< "Capacity: "<< v.capacity()<< endl; 57 | 58 | // reserve() 59 | 60 | // element access 61 | 62 | cout<<"Element at index 3: "<< v.at(3)<< endl; 63 | cout<< "Front element: "<< v.front()<< endl; 64 | cout<< "Last element: "<< v.back()<< endl; 65 | 66 | // modifiers 67 | 68 | vector v2; 69 | v.assign(10, 69); // fill vector with 69 ten times 70 | cout<< "Vector(2nd) elements: "; 71 | printVector(v); 72 | 73 | return 0; 74 | } -------------------------------------------------------------------------------- /Containers/stack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasikahmed/StandardTemplateLibrary-CPP/f38b6e0319398b769471de900c2f8041ba8cd096/Containers/stack -------------------------------------------------------------------------------- /Containers/stack.cpp: -------------------------------------------------------------------------------- 1 | // LIFO -> last in first out 2 | 3 | // functions 4 | // empty(), size(), push(), pop(), top() 5 | 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | 13 | stack s; 14 | 15 | s.push(10); 16 | s.push(20); 17 | 18 | for(int i=20; i<100; i=i+10) { 19 | s.push(i); 20 | } 21 | 22 | cout<< "Stack size: "<< s.size()<< endl; 23 | 24 | cout<< "Stack elements: "<< endl; 25 | stack copyStack = s; 26 | while(!copyStack.empty()) { 27 | cout<< copyStack.top()<< endl; 28 | copyStack.pop(); 29 | } 30 | 31 | // deleting elements 32 | cout<< "Deleting last 5 elements\n"; 33 | for(int i=0; i<5; i++) { 34 | s.pop(); 35 | } 36 | 37 | cout<< "Stack size: "<< s.size()<< endl; 38 | 39 | cout<< "Stack elements: "<< endl; 40 | copyStack = s; 41 | while(!copyStack.empty()) { 42 | cout<< copyStack.top()<< endl; 43 | copyStack.pop(); 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /PriorityQueue/minHeapPriorityQueue: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasikahmed/StandardTemplateLibrary-CPP/f38b6e0319398b769471de900c2f8041ba8cd096/PriorityQueue/minHeapPriorityQueue -------------------------------------------------------------------------------- /PriorityQueue/minHeapPriorityQueue.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | int main() 8 | { 9 | 10 | int arr[5] = { 90, 5, 3, 100, 200}; 11 | 12 | priority_queue, greater > pq(arr, arr+5); 13 | 14 | cout<< "Priority queue: "; 15 | while (!pq.empty()) 16 | { 17 | cout<< pq.top()<< " "; 18 | pq.pop(); 19 | } 20 | cout<< endl; 21 | 22 | cout<< "again: "; 23 | while (!pq.empty()) 24 | { 25 | cout<< pq.top()<< " "; 26 | pq.pop(); 27 | } 28 | cout<< endl; 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /PriorityQueue/priorityQueue: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasikahmed/StandardTemplateLibrary-CPP/f38b6e0319398b769471de900c2f8041ba8cd096/PriorityQueue/priorityQueue -------------------------------------------------------------------------------- /PriorityQueue/priorityQueue.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | int main() 8 | { 9 | priority_queue pq; 10 | int n; 11 | cin>> n; 12 | 13 | int arr[n]; 14 | for(int i=0; i> arr[i]; 16 | } 17 | 18 | cout<< "Input array: "; 19 | for(auto &i : arr) { 20 | cout<< i<< " "; 21 | } 22 | cout<< endl; 23 | 24 | for(int i=0; i