S
simpelthen
Guest
Tja, jeg har en tabel gemt i en fil og ønsker at skrive en QuickSort slags kode, som indlæser data i en tabel og quicksort algoritme på et bord, jeg har en side (kan ikke huske adressen).Jeg kender en lille C og forårsagede et par bugs her.Kunne nogen bare lave dem?Code:
# Inkluder <stdio.h>
# Inkluder <string.h>
quickSortMain void (char emner [] [200], int count);
void QuickSort (int emner [] [200], int venstre, int højre);
int main ()
(
char str [200];
FILE * file_in;
int p, i;file_in = fopen ("file.txt", "r");
p = 0;
printf ("Load array: \ n");
while (! feof (file_in))
(
fscanf (file_in, "% c", & str. );
printf ("% c", str. );
p ;
)quickSortMain (str, 5);for (i = 0; i <5; i ) (
printf ('% s', str. );
)
return 0;
)
quickSortMain void (char emner [] [200], int count)
(
QuickSort (post, 0, count-1);
)void QuickSort (int emner [] [200], int venstre, int højre)
(
int i, j;
char * X;
char temp [10];i venstre =;
j = højre;
x = emner [(venstre højre) / 2];do (
mens ((strcmp (post , x) <0) & & (i <højre)) (
i ;
)
mens ((strcmp (post [j], x)> 0) & & (j> venstre)) (
j -;
)
if (i <= j) (
strcpy (temp, emner );
strcpy (post , elementer [j]);
strcpy (post [j], temp);
i ;
j -;
)
/) Mens (i <= j);if (venstre <j) (
QuickSort (post, venstre, j);
)
if (i <højre) (
QuickSort (post, i, højre);
)
)
# Inkluder <stdio.h>
# Inkluder <string.h>
quickSortMain void (char emner [] [200], int count);
void QuickSort (int emner [] [200], int venstre, int højre);
int main ()
(
char str [200];
FILE * file_in;
int p, i;file_in = fopen ("file.txt", "r");
p = 0;
printf ("Load array: \ n");
while (! feof (file_in))
(
fscanf (file_in, "% c", & str. );
printf ("% c", str. );
p ;
)quickSortMain (str, 5);for (i = 0; i <5; i ) (
printf ('% s', str. );
)
return 0;
)
quickSortMain void (char emner [] [200], int count)
(
QuickSort (post, 0, count-1);
)void QuickSort (int emner [] [200], int venstre, int højre)
(
int i, j;
char * X;
char temp [10];i venstre =;
j = højre;
x = emner [(venstre højre) / 2];do (
mens ((strcmp (post , x) <0) & & (i <højre)) (
i ;
)
mens ((strcmp (post [j], x)> 0) & & (j> venstre)) (
j -;
)
if (i <= j) (
strcpy (temp, emner );
strcpy (post , elementer [j]);
strcpy (post [j], temp);
i ;
j -;
)
/) Mens (i <= j);if (venstre <j) (
QuickSort (post, venstre, j);
)
if (i <højre) (
QuickSort (post, i, højre);
)
)