textbook algorithms in C