# 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

### 1 Answer

- PuzzlingLv 76 years agoFavorite Answer
DESCRIPTION:

The routine will take an array of numbers and perform a "bubble" sort to get them into ascending order.

INPUT:

The routine will take an array of numbers (of a certain size) in an arbitrary order.

BODY:

DO

changed = 0

FOR I = 1 TO size -1

IF nums(I) > nums(I + 1) THEN

# Swap

tmp = nums(I)

nums(I) = nums(I + 1)

nums(I + 1) = tmp

changed = 1

END IF

NEXT

LOOP WHILE(NOT changed)

OUTPUT:

The routine will return that same array of numbers sorted in ascending order.

- Login to reply the answers