Created
September 21, 2016 11:07
-
-
Save devils-ey3/3651dcf07f4467103fa6b6c936edd59d to your computer and use it in GitHub Desktop.
Merge sort by C
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
#include <stdio.h> | |
int main () | |
{ | |
int array [100],array1[100],main[100]; | |
int maxi_index,j,maxi_index1; | |
scanf("%d",&maxi_index); | |
array [maxi_index]; | |
for (j=0; j<maxi_index; j++) | |
scanf("%d",&array [j]); | |
scanf("%d",&maxi_index1); | |
array1 [maxi_index1]; | |
for (j=0; j<maxi_index1; j++) | |
scanf("%d",&array1 [j]); | |
int i=0,k=-1; | |
j=0; | |
while (i<maxi_index && j<maxi_index1) | |
{ | |
if (array[i]<array1[j]) | |
{ | |
k++; | |
main[k]=array[i]; | |
i++; | |
} | |
else | |
{ | |
k++; | |
main[k]=array1[j]; | |
j++; | |
} | |
} | |
int r; | |
if (i<=maxi_index) | |
{ | |
for (r=i;r<maxi_index;r++) | |
main[++k]=array[j]; | |
} | |
else | |
{ | |
for (r=j;r<maxi_index1;r++) | |
main[++k]=array[r]; | |
} | |
for (r=0;r<k;r++) | |
printf("%d ",main[r]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment