I'm trying to make a bubble sort. Here's what I have:
#include <iostream>
#include <vector>
using namespace std;
int main() {
double small;
double big;
double i;
vector<double>list;
while(cin){
cin>>i;
list.push_back(i);
}
for(i=0;i<list.size()-1;i++){
small=list[i];
big=list[i+1];
if(small<=big){
}
else{
list[i]=big;
list[i+1]=small;
}
}
for(i=0;i<list.size()-1;i++)
cout<<list[i]<<'\n';
return 0;
}
Here's my input:
123
4141
515
231366
21378
12990
5
6
8
9
but it outputs this:
123
515
4141
21378
12990
5
6
8
9
9
231366
The expected output should be: 5,6,8,9,123,515,4141,12990,21378,231366.(Ignore this, I was being dumb, the output is correct besides for the duplicated number). Any help? Sorry if this trivial.