Chapter 1 Problem 7 in Data Structures book by Sahini