forked from DSC-COEA-Ambajogai/Hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubbleSort.cpp
42 lines (34 loc) · 796 Bytes
/
bubbleSort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;
void binarySort(int arr[], int n){
int i, j;
for(i = 0; i < n; i++){
for(j = 0; j < n-i-1; j++){
if(arr[j] > arr[1 + j]){
int temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}
}
cout<<"After Sorting: "<<endl;
for(i = 0; i < n; i++)
cout << arr[i]<<" ";
}
int main()
{
int n;
cout << "Enter the number of elements: ";
cin >> n;
int *arr = new int[n];
cout<<"Enter the elements:"<<endl;
for(int i = 0; i < n; i++){
cin >> arr[i];
}
cout <<"Before Sorting: "<<endl;
for(int i = 0; i < n; i++)
cout <<arr[i]<<" ";
cout<<endl;
binarySort(arr, n);
return 0;
}