-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from chiragchandnani10/main
Added Merge Sort Algorithm cpp
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
chiragchandnani10 | ||
https://github.com/chiragchandnani10 | ||
*/ | ||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
void merging(int input[],int start,int end){ | ||
int mid = (start+end)/2; | ||
int i=start, j=mid+1, k=start; | ||
int ans[end+1]; | ||
while(i<=mid&&j<=end){ | ||
if(input[i]<input[j]){ | ||
ans[k]=input[i]; | ||
i++; | ||
k++; | ||
} | ||
else{ | ||
ans[k]=input[j]; | ||
j++; | ||
k++; | ||
} | ||
} | ||
while(i<=mid){ | ||
ans[k]=input[i]; | ||
i++; | ||
k++; | ||
} | ||
while(j<=end){ | ||
ans[k]=input[j]; | ||
j++; | ||
k++; | ||
} | ||
for(int s=start;s<=end;s++){ | ||
input[s]=ans[s]; | ||
} | ||
} | ||
|
||
void merge_sort(int input[],int start,int end){ | ||
if(start>=end){ | ||
return; | ||
} | ||
int mid = ((start+end)/2); | ||
merge_sort(input,start,mid); | ||
merge_sort(input,mid+1,end); | ||
merging(input,start,end); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
void mergeSort(int input[], int size){ | ||
// Write your code here | ||
|
||
merge_sort(input,0,size-1); | ||
|
||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
| Anurag Vats | <a href="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/AnuragVats007">Anurag Vats</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Apurva Dubey | <a href="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/umbridge">umbridge</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
| Daksh Kesarwani | <a href="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/InnocentDaksh63">Daksh kesaarwani</a> | <a href="[email protected]">E-Mail</a> | | ||
| Chirag Chandnani | <a href="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/chiragchandnani10">Chirag Chandnani</a> | <a href="[email protected]">E-Mail</a> | | ||
| Shivam Jaiswal | <a href="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/Shivaminc">Shivam Jaiswal</a> | <a href="[email protected]">E-mail</a> | | ||
| Ashish Kushwaha | <a href="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/AshishKingdom">Ashish Kushwaha</a> | <a href="[email protected]">E-Mail</a> | | ||
| Dhruv Arora | <a href="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/lord-benjamin">Dhruv Arora</a> | <a href="mailto:[email protected]">E-Mail</a> | | ||
|
@@ -50,6 +51,7 @@ | |
|
||
|
||
|
||
|
||
<br> | ||
<h1> | ||
Happy Hacking ❤💻 | ||
|