Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions MergeSort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*This is the code for the Merging Sort function of two Sorted Arrays sorted
in ascending oder toan array containing the elements of both the arrays in ascending order */
void MergeSort(int a[100],int m,int b[100],int n){ //This is the function definition with parametes including the two arrays to be merged sort in ascending order
int c[200];
int k;
for(int i=0;int j=0;i<m;j<n;k++){
if(a[i]<b[j]){ //if the element of the 1st array is less than the element of the 2nd array then send the element to a separate array
c[k]=a[i];
i++; //increment the array by one
}
else{
c[k]=b[j]; //else the element of the 2nd array is to be send to the new array
j++;
}
}
while(i<m){
c[k]=a[i]; //After sorting the elements of the arrays in ascending order, the remaining array elements are added to the array
i++;
k++;
}
while(j<n){
c[k]=b[j]; //After sorting the elements of the arrays in ascending order, the remaining array elements are added to the array
j++;
k++;
}
}