/* mysort.c Jim Plank 7 February, 1994 */ /* This program sorts standard input lexicographically. It uses a red-black tree to do this simply and efficiently. Basically, it reads in a line of input, and inserts it into the tree "sorted_lines". The insertion performs the sorting using strcmp as a comparison function. When it's done reading and inserting, it traverses the tree's linked list, which is guaranteed to be sorted, and prints out each line. */ #include #include #include "rb.h" #include "fields.h" main() { IS is; char *copy; Rb_node sorted_lines, tmp; sorted_lines = make_rb(); is = new_inputstruct(NULL); while(get_line(is) >= 0) { copy = strdup(is->text1); rb_insert(sorted_lines, copy, NULL); } rb_traverse(tmp, sorted_lines) { printf("%s", tmp->k.key); } }