Construct an algorithm that will preform a "bubble" sort in ascending order.?
Construct an algorithm that will preform a "bubble" sort in ascending order. In a bubble sort, we compare the first two elements and swap positions if the first element is larger than the second element. Move the second element and perform the comparison with the third element.Continue the procedure by moving thru the list until you reach the end of the list. Start at the top and repeat the procedure until no more swaps are required, which means that the list is now in sorted order. CREATE ALL components pf an algorithm: DESCRIPTION, INPUT, BODY, OUTPUT
- PuzzlingLv 76 years agoFavorite Answer
The routine will take an array of numbers and perform a "bubble" sort to get them into ascending order.
The routine will take an array of numbers (of a certain size) in an arbitrary order.
changed = 0
FOR I = 1 TO size -1
IF nums(I) > nums(I + 1) THEN
tmp = nums(I)
nums(I) = nums(I + 1)
nums(I + 1) = tmp
changed = 1
LOOP WHILE(NOT changed)
The routine will return that same array of numbers sorted in ascending order.