Skip to content

Commit

Permalink
added bubblesort
Browse files Browse the repository at this point in the history
  • Loading branch information
sanaa-duhh authored and x0lg0n committed Oct 31, 2024
1 parent f60e974 commit 69c6896
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions C++/bubbleSort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;
void bubbleSort(int arr[], int size) {
for (int step = 0; step < size; ++step) {
for (int i = 0; i < size - step; ++i) {
if (arr[i] > arr[i + 1]) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
}
}

void printArray(int arr[], int size)
{
int i;
for (i = 0; i < size; i++)
cout << " " << arr[i];
}

int main()
{
int arr[] = { 64, 34, 25, 12, 22, 11, 90 };
int N = sizeof(arr) / sizeof(arr[0]);
bubbleSort(arr, N);
cout << "Sorted array: \n";
printArray(arr, N);
return 0;
}

0 comments on commit 69c6896

Please sign in to comment.