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
|
#include <iostream>
using namespace std;
void display(int x);
void check_if(int n1, int n2);
int main()
{
int i, j, pass = 0;
int a[10] = { 100,33,49,23,84,2,72,17,82,64 };
cout << "Input list ...\n";
for (i = 0; i < 10; i++) {
display(a[i]);
}
cout << endl;
for (i = 0; i < 10; i++)
{
for (j = i + 1; j < 10; j++)
{
check_if(a[j], a[i]);
}
pass++;
}
cout << "Sorted Element List ...\n";
for (i = 0; i < 10; i++) {
display(a[i]); // Output is wrong
}
cout << "\nNumber of passes taken to sort the list:" << pass << endl;
return 0;
}
void display(int x)
{
cout << x << "\t";
}
void check_if(int n1,int n2)
{
int temp;
if (n1 < n2)
{
temp = n2;
n2 = n1;
n1 = temp;
}
}
| |