Skip to content

Commit

Permalink
Merge pull request #3 from Vishakhasarode/main
Browse files Browse the repository at this point in the history
created bubblesort algorithm using cpp
  • Loading branch information
Khushalsarode authored Oct 23, 2022
2 parents b4e3aa0 + 200c851 commit bb7cc16
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions data-structure/bubble sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <bits/stdc++.h>
using namespace std;
void bubbleSort(int arr[], int n)
{
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < n - i - 1; j++)
if (arr[j] > arr[j + 1])
swap(arr[j], arr[j + 1]);
}
int main()
{
int arr[5] = {5, 2, 7, 9, 1};
int n = sizeof(arr) / sizeof(int);
bubbleSort(arr, n);
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
return 0;
}

0 comments on commit bb7cc16

Please sign in to comment.