Bubble Sort
Bubble Sort
Bubble Sort
SUPERVISOR: Eng/ Noor El-Deen Magdy
Faculty of Engineering,
𝟐𝒏𝒅 Year Computer and Systems Department
Research on the Bubble Sort Algorithm:
Bubble sort works on the repeatedly swapping of adjacent
elements until they are not in the intended order. It is called
bubble sort because the movement of array elements is just
like the movement of air bubbles in the water. Bubbles in
water rise up to the surface; similarly, the array elements in
bubble sort move to the end in each iteration.
How Bubble Sort Works:
The algorithm works by repeatedly "bubbling" the largest unsorted element to
the correct position in each pass. Here’s a step-by-step breakdown:
1. Start from the first element of the list and compare it with the
next element.
2. If the current element is greater than the next, swap them.
3. Move to the next pair of elements and repeat the comparison
and swap process.
4. After each full pass through the list, the largest unsorted element
is placed at its correct position (the end of the list).
5. Repeat the process for the remaining unsorted elements,
ignoring the already sorted portion at the end of the list.
6. The algorithm stops when no more swaps are needed, indicating
the list is fully sorted.
Example:
After the first pass, 8 is in the correct position. Continue with the rest
of the list until fully sorted.
#include <iostream>
using namespace std;