-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f60e974
commit 69c6896
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |