// CS210 - Algorithms and Data Structures I // Department of Computer Science // National University of Ireland, Maynooth // // Solutions to Laboratory Exam 2 // Tom Naughton // January 2001 // //--------------------------------------------------------- //http://www.cs.may.ie/~tnaughton/cs210/ //========================================================= // Problem C public MyClass() { /* Constructor (default). Initialise the array to zero length. */ array = new Comparable[0]; } public MyClass(Comparable e[]) { /* Constructor. Convert an array. */ int count; // counter if (e == null) { array = new Comparable[0]; } else { array = new Comparable[e.length]; count = 0; while (count < e.length) { array[count] = e[count]; count++; } } } public MyClass(MyClass m) { /* Constructor. Copy a MyClass object to a MyClass object (so create ** a copy of the references to the elements of m). */ if (m == null) { array = new Comparable[0]; } else { array = m.toArray(); } }