Unreasonable errors in merge sort

Posted by Alexxx on Stack Overflow See other posts from Stack Overflow or by Alexxx
Published on 2012-01-03T21:18:30Z Indexed on 2012/04/07 11:29 UTC
Read the original article Hit count: 205

Filed under:

i have the following errors - please help me to find the error:

9   IntelliSense: expected a '}'        70  4   

it points on the end of the code - but there are no open { anywhere!! so why??

8   IntelliSense: expected a ';'        57  1   

it points on the { after the void main but why to put ; after the { of the void main??

Error   7   error C1075: end of file found before the left brace '{' at     70  1

points to the beginig of the code - why???

#include <stdio.h>
#include <stdlib.h>

void merge(int *a,int p,int q,int r)
{
  int i=p,j=q+1,k=0;
  int* temp=(int*)calloc(r-p+1, sizeof(int));
  while ((i<=q)&& (j<=r))
        if(a[i]<a[j])
                    temp[k++]=a[i++];
        else 
                    temp[k++]=a[j++];
  while(j<=r)   // if( i>q )
    temp[k++]=a[j++];
 while(i<=q)   //  j>r 
    temp[k++]=a[i++];

  for(i=p,k=0;i<=r;i++,k++)   //  copy temp[] to a[]   
            a[i]=temp[k];
  free(temp);
}

void 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 a[] = {9, 7, 2, 3, 5, 4, 1, 8, 6, 10};
    int i;

    merge_sort(a, 0, 9);

    for (i = 0; i < 10; i++)
        printf ("%d ", a[i]);

© Stack Overflow or respective owner

Related posts about c