Ciao, devo scrivere una funzione mergesort in C. L'ho fatto ma non mi funziona. Il codice è:
File header:codice:#include <stdio.h> #include <stdlib.h> #include "sorting.h" void msort(int a[], int n) { int aux[] = copy(a, aux, n); msort2(a, 0, n - 1, aux); } void msort2(int a[], int fst, int lst, int b[]) { if(fst < lst) { int m = (fst + lst) / 2; msort2(b, fst, m, a); msort2(b, m + 1, lst, a); merge(b, fst, m, lst, a); } } int[] copy(int a[], int aux[], int n) { int i; for(i = 0; i < n; i++) aux[i] = a[i]; return aux; } void merge(int a[], int fst, int mid, int lst, int c[]) { int i = fst; int j = mid + 1; int k = fst; while(i <= mid && j <= lst) { if(a[i] <= a[j]) c[k++] = a[i++]; else c[k++] = a[j++]; } while(i <= mid) c[k++] = a[i++]; while(j <= lst) c[k++] = a[j++]; }
Messaggio d'errore:codice:void msort(int a[], int n); void msort2(int a[], int fst, int lst, int b[]); int[] copy(int a[], int aux[], int n); void merge(int a[], int fst, int mid, int lst, int c[]);
Dove sbaglio? La funzione copy è giusta?codice:In file included from sorting.c:6:0: sorting.h:8:4: error: expected identifier or ‘(’ before ‘[’ token sorting.c: In function ‘msort’: sorting.c:81:2: error: invalid initializer sorting.c: At top level: sorting.c:94:4: error: expected identifier or ‘(’ before ‘[’ token
Grazie![]()

Rispondi quotando
