890 likes | 1.62k Views
Animation of Bubble Sort. Steven Strecker CS510 Computer Algorithms. Kalamazoo College. 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])
E N D
Animation of Bubble Sort Steven Strecker CS510 Computer Algorithms Kalamazoo College
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); }
A NE 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); }
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); }
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) }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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) }
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); }
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) }
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); }
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); }
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) }
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); }
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) }
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); }
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); }
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); }
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) }
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); }
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); }
A A E M N LE 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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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) }
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); }
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) }
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); }
A AE 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); }
A A EL 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); }
A A E LE 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); }