Bubble Sort
Bubble Sort
#include <iostream>
#include <vector>
int n = arr.size();
swapped = true;
if (!swapped) break;
int main() {
int n;
std::cin >> n;
std::vector<int> arr(n);
return 0;
1. Initialize:
If the left element (arr[j]) is greater than the right element (arr[j+1]), swap them.
o After each pass, the largest element is "bubbled" to the end of the array.
o In subsequent passes, reduce the size of the array to consider only the unsorted portion.
4. Optimization (Optional):
o If during a pass no swaps are made, it indicates that the array is already sorted, and you can
terminate the loop early to save time.
PSEUDOCODE::::::
BUBBLE_SORT(arr):
n = size of arr
swapped = false
BREAK