13.07.2015 Aufrufe

Einführung in C/C++ - Alex-weingarten.de

Einführung in C/C++ - Alex-weingarten.de

Einführung in C/C++ - Alex-weingarten.de

MEHR ANZEIGEN
WENIGER ANZEIGEN
  • Keine Tags gefunden...

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

32 KAPITEL 1. PROGRAMMIEREN IN C/<strong>C++</strong><strong>in</strong>t i = 0, j = 0, flag = 0, z, l<strong>in</strong>e[MAXLIN];char array[MAXLIN][LINSIZ];FILE *fp;#if DEBUGpr<strong>in</strong>tf("Bubblesort %s\n", text);#endif/* E<strong>in</strong>lesen */if ((fp = fopen(text, "r")) == NULL) return(-1);while ((!feof(fp)) && (i < MAXLIN)) {fgets(array[i++], LINSIZ, fp);}fclose(fp);#if DEBUGputs("Array:");j = 0;while (j < i) {pr<strong>in</strong>tf("%s", array[j++]);}puts("En<strong>de</strong> Array");#endif/* Sortieren (Bubblesort) */for (j = 0; j < MAXLIN; j++)l<strong>in</strong>e[j] = j;while (flag == 0) {flag = 1;for (j = 0; j < i; j++) {if (strcmp(array[l<strong>in</strong>e[j]], array[l<strong>in</strong>e[j + 1]]) > 0) {z = l<strong>in</strong>e[j + 1];l<strong>in</strong>e[j + 1] = l<strong>in</strong>e[j];l<strong>in</strong>e[j] = z;flag = 0;}}}/* Ausgeben nach stdout */#if DEBUGputs("Array:");j = 0;while (j < i) {pr<strong>in</strong>tf("%d\n", l<strong>in</strong>e[j++]);}puts("En<strong>de</strong> Array");#endifj = 0;while (j < i) {pr<strong>in</strong>tf("%s", array[l<strong>in</strong>e[j++]]);}/* En<strong>de</strong> */return 0;}Quelle 1.15 : C-Funktion Bubblesort

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!