forked from Harshita-Kanal/Data-Structures-and-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbubbleSort.cpp
More file actions
39 lines (35 loc) · 703 Bytes
/
bubbleSort.cpp
File metadata and controls
39 lines (35 loc) · 703 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
39
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int>v;
v.push_back(55);
v.push_back(555);
v.push_back(557);
v.push_back(1);
v.push_back(5);
v.push_back(65);
v.push_back(996);
v.push_back(69);
v.push_back(2);
v.push_back(3);
v.push_back(133);
v.push_back(189);
for(int i = 0 ; i < v.size()-1 ; i++){
int flag = 1;
for(int j = 0 ; j < v.size()-i-1 ; j++){
if(v[j] > v[j+1]){
flag = 0;
v[j+1] = v[j+1] + v[j];
v[j] = v[j+1] - v[j];
v[j+1] = v[j+1] - v[j];
}
}
if(flag){
break;
}
}
for(int i = 0 ; i < v.size() ; i++){
cout << v[i] << " ";
}
return 0;
}