Download presentation
Presentation is loading. Please wait.
1
Animation of Bubble Sort
Steven Strecker CS510 Computer Algorithms Kalamazoo College
2
Introduction void bubble(itemType a[], int N) { int i, j;
for (i = N; i >= 1; i--) for (j = 2; j <= i; j++) if ((a[j-1] > a[j]) swap(a, j-1, j); }
3
A N E X A M P L E void bubbles(itemtype a[], int n) bubbles(a[], 9) {
int i, j; for (i = n; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[2-1] > a[2] no swap(a, j-1, j); }
4
A N E X A M P L E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[2]>a[3]) YES swap(a, j-1, j); }
5
A E N X A M P L E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[2]>a[3]) YES swap(a, j-1, j); swap(a, 2, 3) }
6
A E N X A M P L E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[3]>a[4]) NO swap(a, j-1, j); }
7
A E N X A M P L E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[4]>a[5]) YES swap(a, j-1, j); }
8
A E N A X M P L E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[4]>a[5]) YES swap(a, j-1, j); swap(a, 4, 5); }
9
A E N A X M P L E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[5]>a[6]) YES swap(a, j-1, j); }
10
A E N A M X P L E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[5]>a[6]) YES swap(a, j-1, j); swap(a, 5, 6); }
11
A E N A M X P L E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[6]>a[7]) YES swap(a, j-1, j); }
12
A E N A M P X L E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[6]>a[7]) YES swap(a, j-1, j); swap(a, 6, 7); }
13
A E N A M P X L E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[7]>a[8]) YES swap(a, j-1, j); }
14
A E N A M P L X E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[7]>a[8]) YES swap(a, j-1, j); swap(a, 7, 8); }
15
A E N A M P L X E void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[8]>a[9]) YES swap(a, j-1, j); }
16
A E N A M P L E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for ( i = 9; i >= 1; i--) for (j = 2; j <= i; j++) for (j = 2; j <= 9; j++) if ((a[j-1] > a[j]) if (a[8]>a[9]) YES swap(a, j-1, j); swap(a, 8, 9); }
17
A E N A M P L E X void bubbles(itemType a[], int N) { int i, j;
for (i = N; i >= 1; i--) for (j = 2; j <= i; j++) if ((a[j-1] > a[j]) swap(a, j-1, j); }
18
A E N A M P L E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[2-1] > a[2]) NO swap(a, j-1, j); }
19
A E N A M P L E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[3-1] > a[3]) NO swap(a, j-1, j); }
20
A E N A M P L E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[4-1] > a[4]) YES swap(a, j-1, j); }
21
A E A N M P L E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[4-1] > a[4]) YES swap(a, j-1, j); swap(a, 3, 4) }
22
A E A N M P L E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[5-1] > a[5]) YES swap(a, j-1, j); }
23
A E A M N P L E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[5-1] > a[5]) YES swap(a, j-1, j); swap(a, 4, 5) }
24
A E A M N P L E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[6-1] > a[6]) NO swap(a, j-1, j); }
25
A E A M N P L E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[7-1] > a[7]) YES swap(a, j-1, j); }
26
A E A M N L P E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[7-1] > a[7]) YES swap(a, j-1, j); swap(a, 6, 7) }
27
A E A M N L P E X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[8-1] > a[8]) YES swap(a, j-1, j); }
28
A E A M N L E P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=8; j++) if ((a[j-1] > a[j]) if (a[8-1] > a[8]) YES swap(a, j-1, j); swap(a, 7, 8) }
29
A E A M N L E P X void bubbles(itemType a[], int N) { int i, j;
for (i = N; i >= 1; i--) for (j = 2; j <= i; j++) if ((a[j-1] > a[j]) swap(a, j-1, j); }
30
A E A M N L E P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=7; j++) if ((a[j-1] > a[j]) if (a[2-1] > a[2]) NO swap(a, j-1, j); }
31
A E A M N L E P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=7; j++) if ((a[j-1] > a[j]) if (a[3-1] > a[3]) YES swap(a, j-1, j); }
32
A A E M N L E P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=7; j++) if ((a[j-1] > a[j]) if (a[3-1] > a[3]) YES swap(a, j-1, j); swap(a, 2, 3) }
33
A A E M N L E P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=7; j++) if ((a[j-1] > a[j]) if (a[4-1] > a[4]) NO swap(a, j-1, j); }
34
A A E M N L E P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=7; j++) if ((a[j-1] > a[j]) if (a[5-1] > a[5]) NO swap(a, j-1, j); }
35
A A E M N L E P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=7; j++) if ((a[j-1] > a[j]) if (a[6-1] > a[6]) YES swap(a, j-1, j); }
36
A A E M L N E P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=7; j++) if ((a[j-1] > a[j]) if (a[6-1] > a[6]) YES swap(a, j-1, j); swap(a, 5, 6); }
37
A A E M L N E P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=7; j++) if ((a[j-1] > a[j]) if (a[7-1] > a[7]) YES swap(a, j-1, j); }
38
A A E M L E N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=7; j++) if ((a[j-1] > a[j]) if (a[7-1] > a[7]) YES swap(a, j-1, j); swap(a, 6, 7); }
39
A A E M L E N P X void bubbles(itemType a[], int N) { int i, j;
for (i = N; i >= 1; i--) for (j = 2; j <= i; j++) if ((a[j-1] > a[j]) swap(a, j-1, j); }
40
A A E M L E N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=6; j++) if ((a[j-1] > a[j]) if (a[2-1] > a[2]) NO swap(a, j-1, j); }
41
A A E M L E N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=6; j++) if ((a[j-1] > a[j]) if (a[3-1] > a[3]) NO swap(a, j-1, j); }
42
A A E M L E N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=6; j++) if ((a[j-1] > a[j]) if (a[4-1] > a[4]) NO swap(a, j-1, j); }
43
A A E M L E N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=6; j++) if ((a[j-1] > a[j]) if (a[5-1] > a[5]) YES swap(a, j-1, j); }
44
A A E L M E N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=6; j++) if ((a[j-1] > a[j]) if (a[5-1] > a[5]) YES swap(a, j-1, j); swap(a, 4, 5) }
45
A A E L M E N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=6; j++) if ((a[j-1] > a[j]) if (a[6-1] > a[6]) YES swap(a, j-1, j); }
46
A A E L E M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=6; j++) if ((a[j-1] > a[j]) if (a[6-1] > a[6]) YES swap(a, j-1, j); swap(a, 5, 6) }
47
A A E L E M N P X void bubbles(itemType a[], int N) { int i, j;
for (i = N; i >= 1; i--) for (j = 2; j <= i; j++) if ((a[j-1] > a[j]) swap(a, j-1, j); }
48
A A E L E M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=5; j++) if ((a[j-1] > a[j]) if (a[2-1] > a[2]) NO swap(a, j-1, j); }
49
A A E L E M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=5; j++) if ((a[j-1] > a[j]) if (a[3-1] > a[3]) NO swap(a, j-1, j); }
50
A A E L E M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=5; j++) if ((a[j-1] > a[j]) if (a[4-1] > a[4]) NO swap(a, j-1, j); }
51
A A E L E M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=5; j++) if ((a[j-1] > a[j]) if (a[5-1] > a[5]) YES swap(a, j-1, j); }
52
A A E E L M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=5; j++) if ((a[j-1] > a[j]) if (a[5-1] > a[5]) YES swap(a, j-1, j); swap(a, 4, 5) }
53
A A E E L M N P X void bubbles(itemType a[], int N) { int i, j;
for (i = N; i >= 1; i--) for (j = 2; j <= i; j++) if ((a[j-1] > a[j]) swap(a, j-1, j); }
54
A A E E L M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=4; j++) if ((a[j-1] > a[j]) if (a[2-1] > a[2]) NO swap(a, j-1, j); }
55
A A E E L M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=4; j++) if ((a[j-1] > a[j]) if (a[3-1] > a[3]) NO swap(a, j-1, j); }
56
A A E E L M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=4; j++) if ((a[j-1] > a[j]) if (a[4-1] > a[4]) NO swap(a, j-1, j); }
57
A A E E L M N P X void bubbles(itemType a[], int N) { int i, j;
for (i = N; i >= 1; i--) for (j = 2; j <= i; j++) if ((a[j-1] > a[j]) swap(a, j-1, j); }
58
A A E E L M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=3; j++) if ((a[j-1] > a[j]) if (a[2-1] > a[2]) NO swap(a, j-1, j); }
59
A A E E L M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=3; j++) if ((a[j-1] > a[j]) if (a[3-1] > a[3]) NO swap(a, j-1, j); }
60
A A E E L M N P X void bubbles(itemType a[], int N) { int i, j;
for (i = N; i >= 1; i--) for (j = 2; j <= i; j++) if ((a[j-1] > a[j]) swap(a, j-1, j); }
61
A A E E L M N P X void bubbles(itemType a[], int N) bubbles(a[], 9) {
int i, j; for (i = N; i >= 1; i--) for (i = 9; i>=1; i--) for (j = 2; j <= i; j++) for (j = 2; j<=2; j++) if ((a[j-1] > a[j]) if (a[2-1] > a[2]) NO swap(a, j-1, j); }
62
A A E E L M N P X void bubbles(itemType a[], int N) { int i, j;
for (i = N; i >= 1; i--) for (j = 2; j <= i; j++) if ((a[j-1] > a[j]) swap(a, j-1, j); }
63
A A E E L M N P X void bubbles(itemType a[], int N) { int i, j;
for (i = N; i >= 1; i--) for (j = 2; j <= i; j++) if ((a[j-1] > a[j]) swap(a, j-1, j); }
64
THE END
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.