/*
 ============================================================================
 Name        : SuperHakce.c
 Author      : SuperHakce
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include 
#include 
#define MAX 100;

void merge(int map[],int result[],int a,int b,int c){
        int i = a,j = b + 1,k = a;;
        while(i != b + 1 && j != c + 1){
            if(map[i] > map[j]){
                result[k ++] = map[j ++];
            }else{
                result[k ++] = map[i ++];
            }
        }
        while(i != b + 1)
            result[k++] = map[i++];
       while(j != c + 1)
          result[k++] = map[j++];
       for(i = a;i <= c;i ++)
            map[i] = result[i];
}

void binarySort(int map[],int result[],int a,int b){
       int c;
        if(a < b){
            c = (a + b) / 2;
            binarySort(map,result,a,c);
            binarySort(map,result,c + 1,b);
            merge(map,result,a,c,b);
        }
}

int main(void) {
    int a[100];
    int b[100];
    int i;
    for(i = 0;i < 100;i ++){
        a[i] = rand() % 500 + 1;
        printf("%d ",a[i]);
    }
    printf("\n");
    binarySort(a,b,0,99);
    for(i = 0;i < 100;i ++){
            printf("%d ",a[i]);
    }
    printf("\n");
    return 0;
}