editedHeapSort - packagesequenceSummary;...

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

View Full Document Right Arrow Icon
package  sequenceSummary; import  java.lang.reflect.Array ; import  java.util.*; /**  * Sorter <T>  represents a set of sorting algorithms over a generic  object  * type.  It has only one public method, which  *  *  @param   <T>  the type (must be comparable)  */ public   class  Sorter<T  extends  Comparable<T>> { static  Random  rand  =  new  Random(); public   static   void  main(String[] argv) { Integer[] array={}; //{1,19,14,2,35,7,3}; Sorter<Integer> s; try { s= new  Sorter<Integer>(); Integer[] copyArray =array; s.heapSort(array); for ( int  i=0; i<array. length ; i++) { System. out .println(array[i]); } } catch (SequenceSummaryException e){ e.printStackTrace(); } } /**  * Enum  representing the various sort algorithms.  */ public   static   enum  sortType { INSERTION_SORT MERGE_SORT QUICK_SORT HEAP_SORT }; /**  * Constructor
Background image of page 1

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

View Full DocumentRight Arrow Icon
 *  @throws  SequenceSummaryException (Note that although we allow  you  * to throw an exception in this method if you so choose, you do  not  * need to do so.)  *  */ public  Sorter()  throws  SequenceSummaryException{ // TODO : implement me! } /**  * Sorts the elements in arr  by the value in the KeyValue object  (the  * elements of type V) (performs in - place sorting.)  *  *  @param  type the type of sorting algorithm to use.  *  @param  arr the array to sort  *  @throws  SequenceSummaryException (Note that although we allow  you  * to throw an exception in this method if you so choose, you do  not  * need to do so.)  */ public   void  sort(Sorter.sortType type, T[] arr)  throws  SequenceSummaryException { switch (type){ case   INSERTION_SORT : insertionSort(arr); break ; case   MERGE_SORT : T[] copyArray=arr; mergeSort(arr, 0, (arr. length -1), copyArray); break ; case   QUICK_SORT : quickSort(arr); break ; case   HEAP_SORT : heapSort(arr); break ; default : System. out .println( "No known sort defined" ); break ; } }
Background image of page 2
/**  * Sorts the array using an intsertion  sort  *  @param  x the generalized array to be sorted
Background image of page 3

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

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

This note was uploaded on 09/07/2011 for the course CS 2110 taught by Professor Francis during the Spring '07 term at Cornell University (Engineering School).

Page1 / 9

editedHeapSort - packagesequenceSummary;...

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

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