forked from shivaylamba/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubbesort.cpp
More file actions
36 lines (34 loc) · 687 Bytes
/
bubbesort.cpp
File metadata and controls
36 lines (34 loc) · 687 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
#include<iostream>
#include<vector>
using namespace std;
void swap(int *a,int *b)
{
int t=*a;*a=*b;*b=t;
}
void solve(vector<int>& arr)
{
int n= arr.size();
for(int i=0;i<n;i++)
{
for(int j=1;j<n-i;j++)
{
if(arr[j-1]>arr[j])
{
swap(&arr[j],&arr[j-1]);
// int temp=arr[j-1];
// arr[j-1]=arr[j];
// arr[j]=temp;
}
}
}
}
int main(int argc, char const *argv[])
{ vector<int> arr{8,3,11,6,16,20,-10,18,5};
solve(arr);
for (int i = 0; i < arr.size(); i++)
{
cout<<arr[i]<<" ";
cout<<endl;
}
return 0;
}