quiz5-questions - EE 322C Data Structures Spring 2009 Quiz...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
EE 322C Data Structures Spring 2009 Quiz 5 Instructor: Ramesh Yerraballi Student: Anirudh Pande Grader: Vinoth Chandar Date: 4/29/09 Due : Wednesday 4/29 in class Total : 100 points 1) Collections.sort(List<T>) method takes any list and sorts it according to the type of objects held in the list. For example, Strings are sorted alphabetically, Integers are sorted by value and Date objects chronologically. [15 points ] a) How is this behavior implemented? Collections.sort is implemented as a modified mergesort, where the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist. The method sorts the specified list into ascending order, according to the natural ordering of its elements. The implementation of the method dumps the specified list into an array, sorts the array, and iterates over the list resetting each element from the corresponding position in the array. The best case of the algorithm offers a n log(n) performance. For the method to work, all elements in the list must implement the Comparable interface. Furthermore, all elements in the list must be mutually comparable, meaning, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the list. Finally, the specified list must be modifiable, but not resizeable. b) List<Integer> lst = new ArrayList<Integer> (); Write java code to provide you a sorted list of integers, lst, in the descending order, using the Collections.sort method. [You cannot use the Collections.reverse method] class sortList implements Comparator
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/17/2010 for the course EE 322C taught by Professor Nettles during the Spring '08 term at University of Texas at Austin.

Page1 / 4

quiz5-questions - EE 322C Data Structures Spring 2009 Quiz...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online