bubble sort
Hello,
Does anyone have a sample of a running source code for a bubble sort.
Karl
Here's an example
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
|
#include <iostream>
using namespace std;
int main()
{
int list[10] = {5,3,8,6,4,1,2,9,7,0};
int l1, l2, tempitem;
for(l1=0;l1<10;l1++) cout << list[l1];
cout << endl;
for(l1=9; l1>0; l1--)
{
for(l2=0; l2<l1; l2++)
{
if(list[l2]>list[l2+1])
{
tempitem = list[l2+1];
list[l2+1] = list[l2];
list[l2] = tempitem;
}
}
}
for(l1=0;l1<10;l1++) cout << list[l1];
cout << endl << "Press Enter to Continue...";
cin.get();
return(0);
}
|
Thanks vendan
Topic archived. No new replies allowed.