code implementation out of the data structure textbooks