class modified from Wiess Data Structs/Algos in Java