JohnnyHollywood
01-31-2002, 08:32 PM
Hi I have the following code, in C++ that I did.
void sortit(char [5][5], int, int);
#include <stdio.h>
#include <iostream.h>
int main()
{
char names[5][5] = {{'C','a','r','l'},
{'J','a','m','e','s'},
{'J','a','n','e','t'},
{'A','l','e','x'},
{'K','a','r','e','n'}};
int i,j;
char a[10][10] = {'C'};
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf("%c",names[i][j]);
printf("\n");
}
sortit(names,i,j);
return 0;
}
//
//
// Modify this sortit function and place it here
//
//
void sortit(char unsorted[5][5], int i, int j)
{
//declare new arrays for multiplier and values and also temps for storage
long int values [5][2] = {{0,0},{1.0},{2,0},{3,0},{4,0}};
long int multiplier [5] = {10000, 5000, 1000, 500, 1};
long int T1, T2;
for(i=0; i<5; i++)
for(j=0;j<5;j++)
values[i][1] += unsorted[i][j] * multiplier [j];
for(i=0; i<5; i++)
for(j=i+1; j<5; j++)
if(values[i][1] > values[j][1])
{
T1 = values[i][0];
T2 = values[i][1];
values[i][0] = values[j][0];
values[j][1] = values[j][1];
values[j][0] = T1;
values[j][1] = T2;
}
for(i=0; j<5; i++)
{
for(j=0; j<5; j++)
cout << unsorted [values[i][0]][j];
cout << "\n";
}
}
This is supposed to sort the names in alphabetical order but its not, its only repeating the names in the original order. I dont know what else to do.
------------------
1.33GHz Athlon
512MB DDR
Epox 8-K7A
2 * 40GB IBM HD's ATA-100
Gainward Geforce 2 Ti 450
SBLive Value
Pioneer 16x DVD Slot Load
Enlight 7237 300W Case
Lite-On 16102B
Microsoft Optical Mouse
Microsoft Natural KeyB
3Com 3C905
Viewsonic E95 19inch
void sortit(char [5][5], int, int);
#include <stdio.h>
#include <iostream.h>
int main()
{
char names[5][5] = {{'C','a','r','l'},
{'J','a','m','e','s'},
{'J','a','n','e','t'},
{'A','l','e','x'},
{'K','a','r','e','n'}};
int i,j;
char a[10][10] = {'C'};
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf("%c",names[i][j]);
printf("\n");
}
sortit(names,i,j);
return 0;
}
//
//
// Modify this sortit function and place it here
//
//
void sortit(char unsorted[5][5], int i, int j)
{
//declare new arrays for multiplier and values and also temps for storage
long int values [5][2] = {{0,0},{1.0},{2,0},{3,0},{4,0}};
long int multiplier [5] = {10000, 5000, 1000, 500, 1};
long int T1, T2;
for(i=0; i<5; i++)
for(j=0;j<5;j++)
values[i][1] += unsorted[i][j] * multiplier [j];
for(i=0; i<5; i++)
for(j=i+1; j<5; j++)
if(values[i][1] > values[j][1])
{
T1 = values[i][0];
T2 = values[i][1];
values[i][0] = values[j][0];
values[j][1] = values[j][1];
values[j][0] = T1;
values[j][1] = T2;
}
for(i=0; j<5; i++)
{
for(j=0; j<5; j++)
cout << unsorted [values[i][0]][j];
cout << "\n";
}
}
This is supposed to sort the names in alphabetical order but its not, its only repeating the names in the original order. I dont know what else to do.
------------------
1.33GHz Athlon
512MB DDR
Epox 8-K7A
2 * 40GB IBM HD's ATA-100
Gainward Geforce 2 Ti 450
SBLive Value
Pioneer 16x DVD Slot Load
Enlight 7237 300W Case
Lite-On 16102B
Microsoft Optical Mouse
Microsoft Natural KeyB
3Com 3C905
Viewsonic E95 19inch