forked from MRL-HSL-Software/Fall2023-MBT2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubblesort.cpp
More file actions
53 lines (49 loc) · 845 Bytes
/
bubblesort.cpp
File metadata and controls
53 lines (49 loc) · 845 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <vector>
using namespace std;
class bubble
{
vector <int> numbers;
public:
void input();
void print();
int sort();
};
void bubble::input()
{
int size;
cout<<"what size vector do you want";
cin>>size;
for (int i = 0; i < size; i++)
{
int number;
cout<<"enter number";
cin>>number;
numbers.push_back(number);
}
}
void bubble::print()
{
for (int i = 0; i < numbers.size(); i++)
{
cout<<numbers[i]<<" ";
}
}
int bubble::sort()
{
int n=numbers.size();
for(int i=0;i<n-1;i++)
for(int j=0;j<n-i-1;j++)
if (numbers[j]>numbers[j+1])
{
swap(numbers[j],numbers[j+1]);
}
}
int main()
{
bubble b;
b.input();
b.sort();
b.print();
return 0;
}