I wrote a short code that receives an array and sorts it.
This was my first time and I have so many error – please if you can
explain to me how to fix and where/what are my mistakes…
All I want to do is to sort the array and print it after sorting.
#include <stdio.h>
int merge_sort(int *a,int first, int last)
{
int middle;
if(first < last)
{
middle=(first+last)/2;
merge_sort(a,first,middle);
merge_sort(a,middle+1,last);
merge(a,first,middle,last);
{
}
void main()
{
int x[] = {1, 2, 3, 1, 3, 0, 6};
int xsize= (sizeof x / sizeof x[0])
merge_sort(x, 0, sizeof x / sizeof x[0]);
for (int i = 0; i < xsize; i++) { printf("%d ", x[i]); } putchar('\n');
}
I could see multiple errors in your program
int xsize= (sizeof x / sizeof x[0])must have a semicolon;at the end.for(int i=0;i<xsize;printf("%d ",x[i]), i++);is not the way to print the elements of the array.merge()is missing –merge(a,first,middle,last);So I went ahead and wrote this sample
mergesortfor your reference. Hope this helps!!