14SortingAlgorithms

# 14SortingAlgorithms - Selection Sort – what’s actually...

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

Gros Morne, Newfoundland CSE 114 – Computer Science I Sorting Algorithms

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

View Full Document
Midterm Exam 2 SBCS Review Session Wednesday 7pm-8:30pm In CS 2129
Sorting - The Selection Sort Algorithm Algorithm (non-decreasing sort): Repeat the following for each element at position j in the array for j = 0 to j = length-2: 1. Find the index of the "minimum" element from position j to length-1. 2. Swap the element at position j with the minimum element. (Why don't we do this for the last element at position j = length-1?)

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.

Unformatted text preview: Selection Sort – what’s actually happening 5 2 5 8 4 2 7 1 1 2 5 8 4 2 7 5 1 2 5 8 4 2 7 5 1 2 2 8 4 5 7 5 1 2 2 4 8 5 7 5 1 2 2 4 8 5 7 5 1 2 2 4 8 7 5 5 1 2 2 4 8 7 5 5 Selection Sort Example public static void selectionSort(int data) { int j, k, min_index; for (j = 0; j <=data.length-2; j++) { min_index = j; for (k = j+1; k <= data.length-1; k++) if (data[k] < data[min_index]) min_index = k; int temp = data[j]; data[j] = data[min_index]; data[min_index] = temp; } }...
View Full Document

## This note was uploaded on 04/13/2010 for the course CSE 114 taught by Professor Tashbook during the Spring '08 term at SUNY Stony Brook.

### Page1 / 5

14SortingAlgorithms - Selection Sort – what’s actually...

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

View Full Document
Ask a homework question - tutors are online