Pick middle element of the list 2 if middle element

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: 29 13 10 29 14 13 10 14 29 13 10 29 14 13 10 14 29 13 10 13 14 29 Pass 1 CPSC 223  ­ ­ Fall 2010 8 9/28/10 Insertion Sort (based on textbook) void insertionSort(Entry theArray, int n) { for(int i = 1; i < n; i++) { Entry next = theArray[i]; int j = i; // insertion index while(j > 0 && theArray[j-1] > next) { theArray[j] = theArray[j-1]; // shift j = j – 1; } // end inner for theArray[j] = next; } // end outer for } CPSC 223  ­ ­ Fall 2010 Binary Search •  Given a sorted list, binary search finds an element in O (log n) time •  Search for an element: 1.  Pick middle elem...
View Full Document

This document was uploaded on 03/18/2014 for the course CPSC 223 at Gonzaga.

Ask a homework question - tutors are online