From 28e4c53a6ccb140aa7852c14f9e0b7878a8c7c6b Mon Sep 17 00:00:00 2001 From: P Aswini Kumar Date: Mon, 31 May 2021 19:46:28 +0530 Subject: [PATCH 1/5] Added sorting algorithm --- c++/bubble-sort.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 c++/bubble-sort.cpp diff --git a/c++/bubble-sort.cpp b/c++/bubble-sort.cpp new file mode 100644 index 0000000..c65f513 --- /dev/null +++ b/c++/bubble-sort.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +void bubblesort(int a[], int asize) { + int n = asize; + + for(int i=0;ia[j+1]){ + int x = *(&a[j]); + *(&a[j]) = *(&a[j+1]); + *(&a[j+1])=x; + } + } + } +} \ No newline at end of file From 2cacf3961621ba25490edaf84df1796995818534 Mon Sep 17 00:00:00 2001 From: P Aswini Kumar Date: Mon, 31 May 2021 22:31:08 +0530 Subject: [PATCH 2/5] Added greedy algorithm --- .vscode/settings.json | 5 +++++ c++/greedy-algo.cpp | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 c++/greedy-algo.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0cba2e6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "iostream": "cpp" + } +} \ No newline at end of file diff --git a/c++/greedy-algo.cpp b/c++/greedy-algo.cpp new file mode 100644 index 0000000..514fa4b --- /dev/null +++ b/c++/greedy-algo.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +void activityselection(int a[], int b[], int n) +{ + int i=0; + cout <<"The index of the activities are: "<< i; + for (int j = 1; j < n; j++) + { + if (a[j] >= b[i]) + { + cout <<" "<< j; + i = j; + } + } +} \ No newline at end of file From 0ea7794b94feb231d5f423a9c9496476ab474e59 Mon Sep 17 00:00:00 2001 From: P Aswini Kumar Date: Tue, 1 Jun 2021 00:38:23 +0530 Subject: [PATCH 3/5] Added Divide and Conquer Algorithm --- c++/div&conq.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 c++/div&conq.cpp diff --git a/c++/div&conq.cpp b/c++/div&conq.cpp new file mode 100644 index 0000000..ef8495f --- /dev/null +++ b/c++/div&conq.cpp @@ -0,0 +1,51 @@ +#include +using namespace std; + +int MedianOfTwoSortedArrays(int a[],int b[],int asize, int bsize){ + int i = 0; + int j = 0; + int count; + int m1 = -1, m2 = -1; + + if((bsize + asize) % 2 == 1) + { + for (count = 0; count <= (asize + bsize)/2; count++) + { + if(i != asize && j != bsize) + { + m1 = (a[i] > b[j]) ? b[j++] : a[i++]; + } + else if(i < asize) + { + m1 = a[i++]; + } + else + { + m1 = b[j++]; + } + } + return m1; + } + + else + { + for (count = 0; count <= (asize + bsize)/2; count++) + { + m2 = m1; + if(i != asize && j != bsize) + { + m1 = (a[i] > b[j]) ? b[j++] : a[i++]; + } + else if(i < asize) + { + m1 = a[i++]; + } + else + { + m1 = b[j++]; + } + } + return (m1 + m2)/2; + } + +} From 168a0ce2bfcb8806afc36a905e94a94313f405ab Mon Sep 17 00:00:00 2001 From: P Aswini Kumar Date: Tue, 1 Jun 2021 00:45:20 +0530 Subject: [PATCH 4/5] Added String Algorithm --- c++/string-algo.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 c++/string-algo.cpp diff --git a/c++/string-algo.cpp b/c++/string-algo.cpp new file mode 100644 index 0000000..798af2d --- /dev/null +++ b/c++/string-algo.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +void NaivePatternSearching(string s1, string s2) +{ + int x = s1.size(); + int y = s2.size(); + + for (int i = 0; i <= y - x; i++) { + int j; + for (j = 0; j < x; j++){ + if (s2[i + j] != s1[j]) + break; + } + + if (j == x) { + cout << "Found at index: "<< i << endl; + } + + } +} \ No newline at end of file From aba83d5f7a70a7c47910c4aaba6ba3bae5d276ee Mon Sep 17 00:00:00 2001 From: P Aswini Kumar Date: Sun, 6 Jun 2021 22:40:35 +0530 Subject: [PATCH 5/5] Final Commit --- c++/bubble-sort.cpp | 16 -------------- c++/div&conq.cpp | 51 --------------------------------------------- c++/greedy-algo.cpp | 16 -------------- 3 files changed, 83 deletions(-) delete mode 100644 c++/bubble-sort.cpp delete mode 100644 c++/div&conq.cpp delete mode 100644 c++/greedy-algo.cpp diff --git a/c++/bubble-sort.cpp b/c++/bubble-sort.cpp deleted file mode 100644 index c65f513..0000000 --- a/c++/bubble-sort.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -using namespace std; - -void bubblesort(int a[], int asize) { - int n = asize; - - for(int i=0;ia[j+1]){ - int x = *(&a[j]); - *(&a[j]) = *(&a[j+1]); - *(&a[j+1])=x; - } - } - } -} \ No newline at end of file diff --git a/c++/div&conq.cpp b/c++/div&conq.cpp deleted file mode 100644 index ef8495f..0000000 --- a/c++/div&conq.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -using namespace std; - -int MedianOfTwoSortedArrays(int a[],int b[],int asize, int bsize){ - int i = 0; - int j = 0; - int count; - int m1 = -1, m2 = -1; - - if((bsize + asize) % 2 == 1) - { - for (count = 0; count <= (asize + bsize)/2; count++) - { - if(i != asize && j != bsize) - { - m1 = (a[i] > b[j]) ? b[j++] : a[i++]; - } - else if(i < asize) - { - m1 = a[i++]; - } - else - { - m1 = b[j++]; - } - } - return m1; - } - - else - { - for (count = 0; count <= (asize + bsize)/2; count++) - { - m2 = m1; - if(i != asize && j != bsize) - { - m1 = (a[i] > b[j]) ? b[j++] : a[i++]; - } - else if(i < asize) - { - m1 = a[i++]; - } - else - { - m1 = b[j++]; - } - } - return (m1 + m2)/2; - } - -} diff --git a/c++/greedy-algo.cpp b/c++/greedy-algo.cpp deleted file mode 100644 index 514fa4b..0000000 --- a/c++/greedy-algo.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -using namespace std; - -void activityselection(int a[], int b[], int n) -{ - int i=0; - cout <<"The index of the activities are: "<< i; - for (int j = 1; j < n; j++) - { - if (a[j] >= b[i]) - { - cout <<" "<< j; - i = j; - } - } -} \ No newline at end of file