merge sort

mail@pastecode.io avatar
unknown
actionscript
a year ago
940 B
2
Indexable
Never
#include<stdio.h>
void merge(int a[10],int up,int lb,int mid){
        printf("dfhjdgj");
    int i,j,k;
    i=lb;
    j=mid+1;
    k=lb;
    while(i<=mid && j<=up){
    
        if(a[i]<a[j]){
            
            a[k]=a[i];
        }
        else{
            a[k]=a[j];
        }
        if(j>=up){
            while(i<mid){
                a[k]=a[i];
            }
        }
         if(i>=mid){
            while(j<=up){
                a[k]=a[j];
            }
        }
        
    }
}
void sort(int up,int lb,int a[10]){
    int mid;
    printf("ghfh");
    if(lb<up){
        mid=(up+lb)/2;
        sort(up,mid,a);
        sort(mid+1,lb,a);
        merge(a,up,lb,mid);
    }
}
int main(){
    int i;
    int a[10]={58,75,4,5,1,6,2,56,34,25},last=9,first=0;
    sort(0,last,a);
    printf("Order of Sorted elements: ");
   for(i=0;i<10;i++)
   printf(" %d",a[i]);
   return 0;
}