Download presentation
Presentation is loading. Please wait.
1
Insertion Sort
2
Learning Objectives Review the Bubble and Selection Sorts
Understand the speed, stability and how the insertion sort works
3
Review Show after each pass of the Bubble Sort Low High
Show after each pass of the Selection Sort
4
Insertion Sort Can you describe how it works? Animation
5
Insertion Sort Details
Speed Stability How it works Your turn Low High
6
Procedure insertion(var theArray:theArrayType; size:integer);
dummy:integer; pass, check:integer; Begin for pass:= 2 to size do begin dummy:= theArray[pass]; check := pass-1; while (theArray[check]>dummy) and (check>=1) do theArray[check+1] := theArray[check]; check:=check-1; end; theArray[check+1] := dummy; End;
7
Program Options Sort Race Name, height (in inches) Sort
Randomly generate integers (from 1-100) Time how long it takes the insertion sort to put the values in order. Push: Time sorting the same values with all of the sorts and rate their speed. Name, height (in inches) Sort Input: 10 names and heights Output: The names and corresponding heights in a chart sorted by age using an Insertion sort. Push: Let the user decide if they want to sort by height or name, then sort and show the chart. Push: Input an unknown number of names and heights to sort.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.