Monday, February 22, 2010

lab 3, together with homework at the bottom

void swap(int &a, int &b)
{
int t = a;
a = b;
b = t;
}

void bubblesort(int a[][10], int col)
{
for (int n = 0; n < 10; n++)
{
for (int i = 0; i < 9; i++)
if (a[i][col] > a[i+1][col])
swap(a[i][col], a[i+1][col]);
}
}


int a[10][10];
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
cin >> a[i][j];

for (i = 0; i < 10; i++)
bubblesort(a, i);


for (i = 0; i < 10; i++, cout << endl)
for (int j = 0; j < 10; j++)
cout << a[i][j];
cin >> num;
t = num;
char picture[9][5];
for (int i = 0; i < 9; i++)
for (int j = 0; j < 5; j++)
picture[i][j] = ' ';

for (i = 0; i < 5; i++)
{
int digit = num % 10;
num /= 10;
draw(picture, digit, 5 - i);
}


for (int i = 0; i < 9; i++, cout << endl)
for (int j = 0; j < 5; j++)
cout << picture[i][j];


HW: read up on templatized functions
write a templatized bubblesort and selection sort
http://www.cplusplus.com/doc/tutorial/templates/

No comments:

Post a Comment