Last active
August 29, 2015 14:24
-
-
Save Pr3d4dor/1ffa0a8d0146570f6ad4 to your computer and use it in GitHub Desktop.
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
//Merge sort function in c | |
void mergeSort(int *vet,int *vetAux,int left,int right){ | |
int middle; | |
if (left<right){ | |
middle=(left+right)/2; | |
mergeSort(vet,vetAux,left,middle); | |
mergeSort(vet,vetAux,middle+1,right); | |
insert(vet,vetAux,left,middle+1,right); | |
} | |
} | |
void insert(int *vet,int *vetAux,int ini1,int ini2,int end2){ | |
int in1=ini1,in2=ini2,end1=in2-1,au=0,i; | |
while ((in1<=end1)&&(in2<=end2)){ | |
if (vet[in1]<vet[in2]) | |
vetAux[au++]=vet[in1++]; | |
else | |
vetAux[au++]=vet[in2++]; | |
} | |
while (in1<=end1) | |
vetAux[au++]=vet[in1++]; | |
while (in2<=end2) | |
vetAux[au++]=vet[in2++]; | |
for (i=0;i<au;i++) | |
vet[i+ini1]=vetAux[i]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment