Professional Documents
Culture Documents
Bubble Sort
Bubble Sort
Bubble Sort
Index
1 97 A[1] 97
Array, A
2 82 A[2] 82
3 76 A[3] 76
4 29 A[4] 29
5 17 A[5] 17
1 76 29 29 (1,2) (2,3)
2 29 76 17 J <- 1 to 2
3 17 17 76 Pass-3 J <- 1 to (5-3)
4 82 82 82 ( j, j+1)
5 97 97 97
1 29 17 (1,2)
2 17 29 J <- 1 to 1
3 76 76 Pass-4 J <- 1 to (5-4)
4 82 82 ( j, j+1)
5 97 97
N numbers Pass
i <- 1 to N-1
J <- 1 to (N-3) Pass-3 J <- 1 to ( N-i )
If A[j] > A[j+1) then
Interchange A[j] and A[j+1]