Hi@all
I'm learning the bubble sort from my textbook. I just wrote a small program but something is wrong about output. I couldn't see my mistake. Please help me to see what is wrong with it.
Thanks
Code:
#include <iostream>
using namespace std;
const int size=5;
int main()
{
int m=0;
int array[size];
int counter=0;
cout <<"Enter some integers "<<endl;
cin >>array[m];
while (!cin.eof())
{
m++;
counter++;
cin>>array[m];
}
for(int m=0; m<counter-1; m++)
{
int holder=0;
for (int i=0; i<counter-1; i++)
{
int j=i;
if (array[i]>array[j++])
{
holder=array[j];
array[i]=array[j];
array[i]=holder;
}
}
}
for (int i=0; i<counter; i++)
cout <<array[i]<<" ";
return 0;
}