Binary Search STL

In this program, we will see, how to find an element in the sorted array. #include <iostream> #include <algorithm> using namespace std; int main() { int arr[] = {10, 20, 30, 40, 50, 60, 100, 100}; int n = sizeof(arr) / sizeof(int); //Search -- Key int key; cout << "Enter the Key" << endl; cin … Continue reading Binary Search STL

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++