java notes

# java notes - LINEAR SEARCH BINARY SEARCH SELECTION SORT...

This preview shows pages 1–10. Sign up to view the full content.

LINEAR SEARCH BINARY SEARCH

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

View Full Document
SELECTION SORT
INSERTION SORT

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

View Full Document
BUBBLE SORT
QUICK SORT Find Partition (Quick Sort’s helper method)

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

View Full Document
MERGE SORT

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

View Full Document
HEAP SORT public class HeapSorter { private static int [] a; private static int n; public static void sort( int [] a0) { a=a0; n=a.length; heapsort(); } private static void heapsort() { buildheap(); while (n>1) { n--; exchange (0, n); downheap (0); } } private static void buildheap() { for ( int v=n/2-1; v>=0; v--) downheap (v); } private static void downheap( int v) { int w=2*v+1; // first descendant of v while (w<n) { if (w+1<n) // is there a second descendant? if (a[w+1]>a[w]) w++; // w is the descendant of v with maximum label if (a[v]>=a[w]) return ; // v has heap property // otherwise exchange(v, w); // exchange labels of v and w v=w; // continue w=2*v+1; } } private static void exchange( int i, int j) { int t=a[i]; a[i]=a[j]; a[j]=t; }
} // end class HeapSorter HEAP SORT public class Heapsort { /** * The main method illustrates the use of a heapsort to sort a

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/15/2010 for the course COMPSCI Comp 143 taught by Professor Topham during the Winter '07 term at Shoreline.

### Page1 / 10

java notes - LINEAR SEARCH BINARY SEARCH SELECTION SORT...

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

View Full Document
Ask a homework question - tutors are online