Containers in STL – C++

1) Sequential Containers It implements data structure which can be accessed in a sequential manner. vectorlistdequearraysforward_list 2) Container Adaptors It provides a different interface for sequential containers. queuepriority_queuestack 3) Associative Containers It implements sorted data structures that can be quickly searched(O(logn) time complexity. setmultisetmapmultimap 4) Unordered Associative Containers It implements unordered data structure that can … Continue reading Containers in STL – C++

Search an element in array using find() function

C++ Program #include <iostream> #include <algorithm> using namespace std; int main() { int arr[] = {1, 11, 10, 9, 100}; int n = sizeof(arr) / sizeof(int); //Search -- Key int key; cout << "Enter the Key" << endl; cin >> key; auto itr = find(arr, arr + n, key); int index = itr - arr; … Continue reading Search an element in array using find() function

Sorting in C++

#include <iostream> #include <algorithm> #include <string> using namespace std; bool compare(string s1, string s2) { if (s1.length() == s2.length()) return s1 < s2; return s1.length() > s2.length(); } int main() { int n; cout << "Enter the number" << endl; cin >> n; cin.get(); string s[100]; for (int i = 0; i < n; i++) … Continue reading Sorting in C++

String class : C++

#include <iostream> #include <string> using namespace std; int main() { //string intialization string s0; string s1("Mei"); string s2 = "Meikandanathan"; string s3(s1); string s4 = s2; char arr[] = {'a', 'b', 'c', '\0'}; string s5(arr); cout << s0 << endl; cout << s1 << endl; cout << s2 << endl; cout << s3 << endl; … Continue reading String class : C++