24.02.2013 Aufrufe

Einf ¨uhrung in UNIX - CIS

Einf ¨uhrung in UNIX - CIS

Einf ¨uhrung in UNIX - CIS

MEHR ANZEIGEN
WENIGER ANZEIGEN

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

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

2.7 Writer’s Workbench 185<br />

long time1, time2;<br />

/* Pruefung der Kommandozeile */<br />

if (argc != 2) {<br />

puts(USAGE); return(-1);<br />

}<br />

/* Pruefung des Textfiles */<br />

if (access(argv[1], 0)) {<br />

puts(NOTEXIST); return(-2);<br />

}<br />

if (access(argv[1], 4)) {<br />

puts(NOTREAD); return(-3);<br />

}<br />

/* Sortierfunktion und Zeitmessung */<br />

time1 = time((long *)0);<br />

if (bubble(argv[1])) {<br />

puts(NOTSORT); return(-4);<br />

}<br />

time2 = time((long *)0);<br />

/* Ende */<br />

pr<strong>in</strong>tf("Das Sortieren dauerte %ld sec.\n", time2 - time1);<br />

return 0;<br />

}<br />

Programm 2.36 : C-Programm Sortieren, für RCS<br />

Hier die Funktion zum Sortieren (Bubblesort, nicht optimiert). Der e<strong>in</strong>zige<br />

Witz <strong>in</strong> dieser Funktion ist, daß wir nicht die Str<strong>in</strong>gs durch Umkopieren sortieren,<br />

sondern nur die Indizes der Str<strong>in</strong>gs. Ansonsten kann man hier noch<br />

e<strong>in</strong>iges verbessern und vor allem auch andere Sortieralgorithmen nehmen.<br />

Man sollte auch das E<strong>in</strong>lesen und die Ausgabe vom Sortieren trennen:<br />

/* Funktion bubble() (Bubblesort), als Beispiel fuer RCS<br />

W. Alex, Universitaet Karlsruhe, 04. Juli 1995 */<br />

/*<br />

*/<br />

$Header: bubble.c,v 1.2 95/07/04 18:11:04 wualex1 Exp $<br />

#<strong>in</strong>clude &#60;stdio.h&#62;<br />

#<strong>in</strong>clude &#60;str<strong>in</strong>g.h&#62;<br />

#<strong>in</strong>clude "myheader.h"

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

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!