#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int a[100];
int b[100];
void my_copy(int m, int n){
int i;
for(i = m; i <= n; i++){
a[i] = b[i - m];
}
}
void merge_sort(int m, int n){
int i, j, k, temp1;
if(m == n){
return ;
}
temp1 = (m + n) / 2;
merge_sort(m, temp1);
merge_sort(temp1 + 1, n);
k = 0;
for(i = m, j = temp1 + 1; i <= temp1 && j <= n; k++){
if(a[i] < a[j]){
b[k] = a[i];
i++;
}
else{
b[k] = a[j];
j++;
}
}
while(i <= temp1){
b[k++] = a[i];
i++;
}
while(j <= n){
b[k++] = a[j];
j++;
}
my_copy(m, n);
memset(b, 0, sizeof(b));
}
int main()
{
int N, i;
printf("Enter the quality: ");
scanf("%d", &N);
printf("Enter the number: ");
for(i = 0; i < N; i++){
scanf("%d", &a[i]);
}
merge_sort(0, N - 1);
for(i = 0; i < N; i++){
printf("%-4d", a[i]);
}
printf("\n");
return 0;
}
#include<stdlib.h>
#include<string.h>
int a[100];
int b[100];
void my_copy(int m, int n){
int i;
for(i = m; i <= n; i++){
a[i] = b[i - m];
}
}
void merge_sort(int m, int n){
int i, j, k, temp1;
if(m == n){
return ;
}
temp1 = (m + n) / 2;
merge_sort(m, temp1);
merge_sort(temp1 + 1, n);
k = 0;
for(i = m, j = temp1 + 1; i <= temp1 && j <= n; k++){
if(a[i] < a[j]){
b[k] = a[i];
i++;
}
else{
b[k] = a[j];
j++;
}
}
while(i <= temp1){
b[k++] = a[i];
i++;
}
while(j <= n){
b[k++] = a[j];
j++;
}
my_copy(m, n);
memset(b, 0, sizeof(b));
}
int main()
{
int N, i;
printf("Enter the quality: ");
scanf("%d", &N);
printf("Enter the number: ");
for(i = 0; i < N; i++){
scanf("%d", &a[i]);
}
merge_sort(0, N - 1);
for(i = 0; i < N; i++){
printf("%-4d", a[i]);
}
printf("\n");
return 0;
}