Sorting
45
77
10
-7
29
12
72
80
53
41
22
-7
10
12
22
29
41
45
53
72
77
80
WHY? ...to make the searching process faster, since binary search can be performed on a sorted array only.
45
77
10
-7
29
12
72
80
53
41
22
failed
-8
14
24
29
31
45
52
54
60
72
76
81
success
BUBBLE SORT
BUBBLE SORT
start from 0 to N-2, perform the following steps. compare the current element to the next element. if the current element is greater than the next, then swap them. repeat the entire process (N-1) times.
45
77
10
-7
29
45
77
10
-7
29
1 pass
45
77
10
-7
29
1st progress
45
10
77
-7
29
45
10
-7
77
29
45
10
-7
29
77
45
10
-7
29
77
45
10
-7
29
77
1 pass
10
45
-7
29
77
2nd progress
10
-7
45
29
77
10
-7
29
45
77
10
-7
29
45
77
10
-7
29
45
77
10
-7
29
45
77
1 pass
-7
10
29
45
77
3rd progress
-7
10
29
45
77
-7
10
29
45
77
-7
10
29
45
77
-7
10
29
45
77
-7
10
29
45
77
1 pass
-7
10
29
45
77
4th progress
-7
10
29
45
77
-7
10
29
45
77
-7
10
29
45
77
OK, in this case we need only 4 passes to make the sorted one. The next step, in this case, is uneccessary.
-7
10
29
45
77
-7
10
29
45
77
1 pass
-7
10
29
45
77
5th progress
-7
10
29
45
77
-7
10
29
45
77
-7
10
29
45
77
In a worst case, this pass must be performed. Hence, the case in which initial position of the lowest value in the most right element.
2 DO 2 DO THEN 1])
give initial condition for X = N 1. compare all elements from 0 to X. find the greatest, swap it into element X. subtract X with 1. repeat from 2nd step until X reaches 0.
1 pass
45
77
10
-7
29
1st progress
45 29 2 10 -7 77
1 pass
45
29
10
-7
77
2nd progress
-7 29 2 10 45 77
1 pass
-7
29
10
45
77
3rd progress
-7 10 2 29 45 77
1 pass
-7
10
29
45
77
4th progress
-7 2 10 29 45 77
OK, in this case we need only 4 passes to make the sorted one. The next step, in this case, is uneccessary.
1 pass
-7
10
29
45
77
5th progress
-7 2 10 29 45 77
In a worst case, this pass must be performed. Hence, the case in which initial position of the lowest value in the most right element.
ROUTINE TASKS you have array which contains 300 elements, and every element is a record structured with name, address, reg num, score, and age. fill them with random value, make sure no duplicate in reg num, and make sure the reg num is absolutely randomized (unsorted). create a function (Sort_By_RegNum) to sort this array by reg num.
WHATS NEXT?