-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble_sort1.cpp
More file actions
38 lines (35 loc) · 781 Bytes
/
Copy pathbubble_sort1.cpp
File metadata and controls
38 lines (35 loc) · 781 Bytes
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
#include<iostream>
using namespace std;
void bubble(int arr[],int n){
for (int i = n-1; i>=0; i--)
{
int didswap = 0;
for (int j = 0; j <= i-1; j++)
{
if (arr[j] > arr[j+1])
{
int temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
didswap=1;
}
}
if (didswap==0){
break;
}
}
}
int main(){
int n;
cout<<" Enter the size of array :";
cin >> n;
cout << "enter the values of the given array of size " << n << endl;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
bubble(arr,n);
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
return 0;
}