Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 2 Getting an unknown # of …. Into an array.

Similar presentations


Presentation on theme: "Computer Science 2 Getting an unknown # of …. Into an array."— Presentation transcript:

1 Computer Science 2 Getting an unknown # of …. Into an array.
Looking at another type of sort.

2 Learning Objectives Review Bubble Sort
Be able to put an unknown number of items into an array. Understand how a Selection Sort Works Be able to write a program that uses the selection sort.

3 Bubble Sort Speed = Stability = How it works =

4 Warm up Show the following after each pass of the Bubble Sort High Low

5 How can you store an unknown number of Song Titles into an array?
Type Songtype = array[1..100] of string; Var Songs:songtype; numberOfSongs:integer;

6 Pseudo Code Use a while loop to get the information (Semantics of a while loop!) In the condition part of the while loop also check to make sure the user does not go beyond the number of elements in the array. Include a count variable to keep track of how many items were added to the array.

7 Code

8 Another Sort Selection Sort
Speed:_________ Stability: _____________ How it works: _____________

9 Showing it after each pass
Low High High Low

10 Selection Sort: Code {*** This is just the sorting code }
for pass:= 1 to size-1 do begin mark:=pass; for check:= pass to size do if numbers[check] < numbers[mark] then mark:=check; {Mark} dummy:=numbers[mark]; {Switch} numbers[mark]:=numbers[pass]; numbers[pass]:= dummy; end; {Of the for pass loop}

11 Program Options Song Sort: Input an unknown number of songs (but less than 100) Show out of order Sort Show in order Push: Let the user also enter the Style of music, and be able to sort by style. Name age sort Input: An unknown number of names and ages Output: The names and corresponding ages in a chart sorted by age. Push: Let the user decide if they want to sort by age or name, then sort and show the chart. Stats are great Input:9 integers Output: The mean, median, mode and range of the values Push: Let the user enter an unknown number of scores, but less than 100 and calculate the above


Download ppt "Computer Science 2 Getting an unknown # of …. Into an array."

Similar presentations


Ads by Google