this is my bubble sort. hope usefull :3
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
|
#include <iostream>
using namespace std;
int main()
{
int number[] = { 4, 2, 7, 4, 5, 1, 9, 8, 7, 3 };
int temp;
cout << "Before sort : ";
for(int i = 0; i < 10; i++)
{
cout <<endl<< number[i]<<endl; // "\t";
}
cout << endl;
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 9 - i; j++)
{
if(number[j] > number[j+1])
{
temp = number[j];
number[j] = number[j+1];
number[j+1] = temp;
}
}
}
cout << "After sort : ";
for(int i = 0; i < 10; i++)
{
cout <<endl<< number[i] <<endl; // "\t";
}
cout << endl;
system("PAUSE");
return 0;
}
|
Last edited on
First, edit your post. Then select all of your code, and press the <> button on the right under the format section.
Alternatively you can type a [ code] before the your program code, and type a [ /code] at the end. Omit the space - I did that so you can see it.
HTH
Last edited on