-
Notifications
You must be signed in to change notification settings - Fork 0
/
BubbleSort.cpp
58 lines (46 loc) · 1.23 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int x, y;
// Vector yerine array tercih edilirse
//int n = 4;
//int arr[4] = { 1, 2, 3, -2 };
//cin >> n;
/*for (int i = 0; i < n; i++) {
cin >> arr[i];
}*/
// with vector
vector<int> V;
int helper;
while (cin >> helper) {
V.push_back(helper);
}
for (int i = 0; i < V.size()-1 ; i++) {
for (int j = 0; j < V.size()- 1; j++) {
x = V[j];
y = V[j + 1];
if (x > y) {
cout << i << " nci eleman icin baslangictaki durum = ";
for (int z = 0; z < V.size(); z++)
{
cout << V[z] << " ";
}
cout << endl;
V[j + 1] = x;
V[j] = y;
cout << i << " nci eleman icin sondaki durum = ";
for (int z = 0; z < V.size(); z++)
{
cout << V[z] << " ";
}
cout << endl << endl;
}
}
}
for (int i = 0; i < V.size() ; i++) {
cout << V[i] << " ";
}
return 0;
}