Skip to content

Commit

Permalink
Merge pull request #137 from chiragchandnani10/main
Browse files Browse the repository at this point in the history
Added Merge Sort Algorithm cpp
  • Loading branch information
AdarshAddee committed Oct 3, 2022
2 parents b9db83a + 335f299 commit cb9790b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
61 changes: 61 additions & 0 deletions C++/Merge_sort.cpp
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);



}

2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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> |
Expand All @@ -50,6 +51,7 @@




<br>
<h1>
Happy Hacking ❤💻
Expand Down

0 comments on commit cb9790b

Please sign in to comment.