C
cpuracr8
i've been looking through the topics here and i can't quite find one
that helps me. i'm trying to sort a struct that contains three arrays
using the sort() function. the three arrays are parallel and need to be
grouped together when it is sorted. for instance, if i sort the int
array by ascending order, i need the name and grade associated with
that int array to also move with it. i hope what i said is not too
confusing. what am i doing wrong? here is the code i'm using:
struct courses {
string student[7];
string idNumber[7];
string score[7];
} course1, course2, temp;
course1.student[0] = "Name";
course1.student[1] = "Name";
....
course1.student[6] = "Name";
course1.idNumber[0] = "001221";
course1.idNumber[1] = "001543";
....
course1.idNumber[6] = "001334";
course1.score[0] = "38";
course1.score[1] = "98";
....
course1.score[6] = "67";
sort(course1.idNumber, course1.idNumber+7)
// end
i realize that sorting like what i have above only sorts that one
array. but since i want all the arrays to be linked to each other, i
need to move the other two arrays to the same position when it sorts
the idNumber. is there a different way to do this? the only stipulation
is that i need to have three parallel arrays for each course1 and
course2.
that helps me. i'm trying to sort a struct that contains three arrays
using the sort() function. the three arrays are parallel and need to be
grouped together when it is sorted. for instance, if i sort the int
array by ascending order, i need the name and grade associated with
that int array to also move with it. i hope what i said is not too
confusing. what am i doing wrong? here is the code i'm using:
struct courses {
string student[7];
string idNumber[7];
string score[7];
} course1, course2, temp;
course1.student[0] = "Name";
course1.student[1] = "Name";
....
course1.student[6] = "Name";
course1.idNumber[0] = "001221";
course1.idNumber[1] = "001543";
....
course1.idNumber[6] = "001334";
course1.score[0] = "38";
course1.score[1] = "98";
....
course1.score[6] = "67";
sort(course1.idNumber, course1.idNumber+7)
// end
i realize that sorting like what i have above only sorts that one
array. but since i want all the arrays to be linked to each other, i
need to move the other two arrays to the same position when it sorts
the idNumber. is there a different way to do this? the only stipulation
is that i need to have three parallel arrays for each course1 and
course2.