+ All Categories
Home > Documents > För algoritm, se figur 6.9 i Java Gently, sidan 179.

För algoritm, se figur 6.9 i Java Gently, sidan 179.

Date post: 21-Dec-2015
Category:
View: 221 times
Download: 2 times
Share this document with a friend
Popular Tags:
126
För algoritm, se figur 6.9 i Java Gently, sidan 179
Transcript
Page 1: För algoritm, se figur 6.9 i Java Gently, sidan 179.

För algoritm, se figur 6.9i Java Gently, sidan 179

Page 2: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

leftmost

chosen

j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 3: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

0chosen

j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 4: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

0chosen

1j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 5: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

0chosen

1j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 6: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

0chosen

1j

a

SANT

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 7: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

1chosen

1j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 8: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

1chosen

2j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 9: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

1chosen

2j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 10: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

1chosen

2j

a

Falskt

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 11: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

1chosen

3j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 12: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

1chosen

3j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 13: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

1chosen

3j

a

Sant

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 14: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

3j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 15: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

4j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 16: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

4j

a

temp

Falskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 17: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

5j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 18: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

5j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 19: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

5j

a

temp

Falskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 20: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

6j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 21: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

6j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 22: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

6j

a

temp

Falskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 23: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

6j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 24: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

6j

a

temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 25: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

6j

a

temp

FalsktFalskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 26: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

2

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

6j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 27: För algoritm, se figur 6.9 i Java Gently, sidan 179.

4

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

6j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 28: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

0leftmost

3chosen

6j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 29: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

3chosen

6j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 30: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

6j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 31: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

2j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 32: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

2j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 33: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

2j

a

2temp

Falskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 34: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

3j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 35: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

3j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 36: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

3j

a

2temp

Falskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 37: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

4j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 38: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

4j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 39: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

4j

a

2temp

Falskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 40: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

5j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 41: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

5j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 42: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

1chosen

5j

a

2temp

Sant

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 43: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

5chosen

5j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 44: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

5chosen

6j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 45: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

5chosen

6j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 46: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

5chosen

6j

a

2temp

Falskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 47: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

5chosen

7j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 48: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

2

5

4

6

5

7

1leftmost

5chosen

7j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 49: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

3

1

8

2

4

3

9

4

3

5

4

6

5

7

1leftmost

5chosen

7j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 50: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

1leftmost

5chosen

7j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 51: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

5chosen

7j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 52: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

2chosen

7j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 53: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

2chosen

3j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 54: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

2chosen

3j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 55: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

2chosen

3j

a

2temp

SANT

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 56: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

3chosen

3j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 57: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

3chosen

4j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 58: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

3chosen

4j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 59: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

3chosen

4j

a

2temp

FALSKT

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 60: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

3chosen

5j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 61: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

3chosen

5j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 62: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

3chosen

5j

a

2temp

Sant

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 63: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

5chosen

5j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 64: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

5chosen

6j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 65: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

5chosen

6j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 66: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

5chosen

6j

a

2temp

Falskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 67: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

5chosen

7j

a

2temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 68: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

3

5

4

6

5

7

2leftmost

5chosen

7j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 69: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

8

2

4

3

9

4

8

5

4

6

5

7

2leftmost

5chosen

7j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 70: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

2leftmost

5chosen

7j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 71: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

5chosen

7j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 72: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

7j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 73: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

4j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 74: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

4j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 75: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

4j

a

3temp

FALSKT

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 76: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

5j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 77: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

5j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 78: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

5j

a

3temp

FALSKT

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 79: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

6j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 80: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

6j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 81: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

6j

a

3temp

FALSKT

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 82: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

7j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 83: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

7j

a

3temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 84: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

7j

a

3temp

FALSKT

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 85: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 86: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 87: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

3leftmost

3chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 88: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

3chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 89: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

4chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 90: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

4chosen

5j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 91: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

4chosen

5j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 92: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

4chosen

5j

a

4temp

Sant

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 93: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

5chosen

5j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 94: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

5chosen

6j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 95: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

5chosen

6j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 96: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

5chosen

6j

a

4temp

Sant

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 97: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

6chosen

6j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 98: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

6chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 99: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

6chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 100: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

6chosen

7j

a

4temp

Falskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 101: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

4

6

5

7

4leftmost

6chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 102: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

9

4

8

5

9

6

5

7

4leftmost

6chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 103: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

4leftmost

6chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 104: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

5leftmost

6chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 105: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

5leftmost

5chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 106: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

5leftmost

5chosen

6j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 107: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

5leftmost

5chosen

6j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 108: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

5leftmost

5chosen

6j

a

4temp

Falskt

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 109: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

5leftmost

5chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 110: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

5leftmost

5chosen

7j

a

4temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 111: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

5leftmost

5chosen

7j

a

4temp

Sant

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 112: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

5leftmost

5chosen

7j

a

4temp

Sant

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 113: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

5

7

5leftmost

5chosen

7j

a

5temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 114: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

8

5

9

6

8

7

5leftmost

5chosen

7j

a

5temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 115: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

9

6

8

7

5leftmost

5chosen

7j

a

5temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 116: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

9

6

8

7

6leftmost

5chosen

7j

a

5temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 117: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

9

6

8

7

6leftmost

6chosen

7j

a

5temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 118: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

9

6

8

7

6leftmost

6chosen

7j

a

5temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 119: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

9

6

8

7

6leftmost

6chosen

7j

a

5temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 120: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

9

6

8

7

6leftmost

6chosen

7j

a

5temp

Sant

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 121: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

9

6

8

7

6leftmost

7chosen

7j

a

5temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 122: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

9

6

8

7

6leftmost

7chosen

7j

a

8temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 123: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

9

6

9

7

6leftmost

7chosen

7j

a

8temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 124: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

8

6

9

7

6leftmost

7chosen

7j

a

8temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 125: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

8

6

9

7

6leftmost

7chosen

7j

a

8temp

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}

Page 126: För algoritm, se figur 6.9 i Java Gently, sidan 179.

2

0

2

1

3

2

4

3

4

4

5

5

8

6

9

7

leftmost

chosen

j

a

temp

FÄRDIGSORTERAT

Static void selectionSort(int[] a, int n){ int temp; int chosen; for(int leftmost = 0: leftmost < n-1. Leftmost++) { chosen = leftmost; for(int j = leftmost + 1; j < n; j++) if(a[j] < a[chosen]) chosen = j; temp = a[chosen]; a[chosen] = a[leftmost]; a[leftmost] = temp; }}


Recommended