CS1110: Computer Science I - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

CS1110: Computer Science I

Description:

Divides the array into two parts: already sorted, and not yet sorted. ... pass, finds the smallest of the unsorted elements, and swap it into its correct ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 12
Provided by: csWm6
Category:

less

Transcript and Presenter's Notes

Title: CS1110: Computer Science I


1
CS1110 Computer Science I
  • Chapter 5
  • Arrays

2
The foreach Statement
  • for (indexVar0 indexVarltarrayName.Length
    indexVar)
  • process arrayNameindexVar
  • foreach (Type variableName in arrayName)
  • statement
  • static void WriteArray(int a)
  • foreach (int element in a)
  • Console.Write(element)

3
Selection Sort
values 0 1 2
3 4
Divides the array into two parts already
sorted, and not yet sorted. On each pass,
finds the smallest of the unsorted elements, and
swap it into its correct place, thereby
increasing the number of sorted elements by one.
36 24 10 6 12
4
Selection Sort Pass One
5
Selection Sort End Pass One
values 0 1 2
3 4
6 24 10 36 12
U N S O R T E D
6
Selection Sort Pass Two
values 0 1 2
3 4
6 24 10 36 12
U N S O R T E D
7
Selection Sort End Pass Two
values 0 1 2
3 4
6 10 24 36 12
U N S O R T E D
8
Selection Sort Pass Three
values 0 1 2
3 4
6 10 24 36 12
U N S O R T E D
9
Selection Sort End Pass Three
values 0 1 2
3 4
S O R T E D
6 10 12 36 24
10
Selection Sort Pass Four
values 0 1 2
3 4
S O R T E D
6 10 12 36 24
11
Selection Sort End Pass Four
values 0 1 2
3 4
6 10 12 24 36
S O R T E D
Write a Comment
User Comments (0)
About PowerShow.com