conversion of some of Sedgewick's Java Algorthms to Scala