From 0cac475b4a587ba1b11d911fab931db26e75011e Mon Sep 17 00:00:00 2001 From: mohibqureshi Date: Mon, 7 Oct 2019 14:17:12 +0530 Subject: [PATCH 1/3] Added Object_Oriented_Programming directory and string simulation with the same. --- .../Object_Oriented_programming/string.cpp | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 Algorithms/Object_Oriented_programming/string.cpp diff --git a/Algorithms/Object_Oriented_programming/string.cpp b/Algorithms/Object_Oriented_programming/string.cpp new file mode 100644 index 0000000..f147595 --- /dev/null +++ b/Algorithms/Object_Oriented_programming/string.cpp @@ -0,0 +1,136 @@ +#include +using namespace std; +class String +{ +private: + char *strArray; + int length; +public: + String () + { + strArray= NULL; + length=0; + } + String (char *char_arr) + { + if (char_arr == NULL) + { + strArray = nullptr; + return; + } + int count=0; + char *p =char_arr; + while (*p != '\0') + { + count++; + p++; + } + length=count; + strArray = new char[count + 1]; + for (int i = 0; i < count; i++) + { + strArray[i] = char_arr[i]; + } + strArray[count]='\0'; + } + String (int len) + { + length = len; + strArray = new char[len + 1]; + } + + String (String &ob1) + { + cout<<"copy constructor"; + int l=getLength(); + ob1.strArray = new char[l + 1]; + for(int i=0;i>s1; + char s2[100]; + cout<<"enter second string\n"; + cin>>s2; + String opp1(s1); + String opp(s2); + st1 = opp1 + opp; + cout<<"concatenated string "<most){ + most=co[i]; + ind=i; + } + } + cout<<"string after removal most occuring character\n"; + for (int m=0;m Date: Mon, 7 Oct 2019 14:20:30 +0530 Subject: [PATCH 2/3] Added Object_Oriented_Programming directory and string simulation with the same. --- Algorithms/Object_Oriented_programming/string.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Algorithms/Object_Oriented_programming/string.cpp b/Algorithms/Object_Oriented_programming/string.cpp index f147595..bdee254 100644 --- a/Algorithms/Object_Oriented_programming/string.cpp +++ b/Algorithms/Object_Oriented_programming/string.cpp @@ -1,3 +1,4 @@ +//string manipulations using oopss #include using namespace std; class String From 1f5037566fe373af2645255929c618fcfcb50356 Mon Sep 17 00:00:00 2001 From: mohibqureshi Date: Mon, 7 Oct 2019 20:20:07 +0530 Subject: [PATCH 3/3] Heap Sort algorithm in C++ --- Algorithms/sorting/heap_sort.cpp | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Algorithms/sorting/heap_sort.cpp diff --git a/Algorithms/sorting/heap_sort.cpp b/Algorithms/sorting/heap_sort.cpp new file mode 100644 index 0000000..805118d --- /dev/null +++ b/Algorithms/sorting/heap_sort.cpp @@ -0,0 +1,68 @@ +#include + +using namespace std; + +void MaxHeapify(int A[], int len, int i) +{ + int left = 2 * i; + int right = (2 * i + 1); + int large = i; + if (left < len && A[left] > A[i]) + { + large = left; + } + else + large = i; + + if (right < len && A[right] > A[large]) + { + large = right; + } + if (large != i) + { + swap(A[i], A[large]); + MaxHeapify(A, len, large); + } +} + +void buildmaxheap(int A[], int n) +{ + int heapsize; + heapsize = n; + for (int i = (n / 2) - 1; i >= 0; i--) + { + MaxHeapify(A, n, i); + } +} + +void HeapSort(int A[], int n) +{ + buildmaxheap(A, n); + for (int i = n - 1; i >= 0; i--) + { + swap(A[0], A[i]); + MaxHeapify(A, i, 0); + } +} + +int main() +{ + int n; + cout << "Enter the length of array" << endl; + cin >> n; + int arr[n]; + cout << "Enter array elements(space separated):" << endl; + for (int i = 0; i < n; i++) + { + cin >> arr[i]; + } + HeapSort(arr, n); + cout << "The sorted array is:" << endl; + for (int i = 0; i < n; i++) + { + cout << arr[i] << " "; + } + cout << endl; + + return 0; +} \ No newline at end of file