Question: Bubble Sort Problem Description: In the bubble sort algorithm, smaller values gradually bubble their way upward to the top of the array like air bubbles
Bubble Sort
Problem Description:
In the bubble sort algorithm, smaller values gradually "bubble" their way upward to the top of the array like air bubbles rising in water, while the larger values sink to the bottom. The bubble sort makes several passes through the array. On each pass, successive pairs of elements are compared. If a pair is in increasing order (or the values are identical), we leave the values as they are. If a pair is in decreasing order, their values are swapped in the array.
You are given an incomplete code for this assignment. You need to complete the following tasks.
1. Implement bubble sort algorithm in the following function.
void bubbleSort(int a[], int size);
2. Complete test cases 3 and 4, respectively in the main() function.
Pseudo-code
set Boolean variable swapped to true
for pass = 0 to size - 2
{
set swapped to false
for j = 0 to size 2 pass
{
if a[j] is greater than a[j+1]
{
swap a[j] with a[j+1]
set swapped to true
}
}
if no elements being swapped
break out of the loop
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
