code based on <Data Structures and Algorithm Analysis in C> (2nd ed)