So, i need help sorting a structure in a c++ simple console app, i need to sort it by the variable "cas"(time), and i can't figure out how to do it because the objects dont have the same name...would apreciate some help, here is the code:
struct tekmovalec
{
int sstevilka;
char ime[10];
char priimek[15];
double cas;
char nacionalnost[3];
char ime_ekipe[15];
}t1,t2,t3,t4,t5,t6;
void uredipocasu()//sortbytime/bubblesort
{
int pom;
for(int i = 0; i < 6; i++)//pass 6 times
{
for(int j = 1; j < 5; j++)
{
if(t[j].cas < t[j+1].cas)
{
pom = t[j].sstevilka;
t[j].sstevilka = t[j+1].sstevilka;
t[j+1].sstevilka = pom;
pom = t[j].ime;
t[j].ime = t[j+1].ime;
t[j+1].ime = pom;
pom = t[j].priimek;
t[j].priimek = t[j+1].priimek;
t[j+1].priimek = pom;
pom = t[j].cas;
t[j].cas = t[j+1].cas;
t[j+1].cas = pom;
pom = t[j].nacionalnost;
t[j].nacionalnost = t[j+1].nacionalnost;
t[j+1].nacionalnost = pom;
pom = t[j].ime_ekipe;
t[j].ime_ekipe = t[j+1].ime_ekipe;
t[j+1].ime_ekipe = pom;
}
}
}
}
struct tekmovalec
{
int sstevilka;
char ime[10];
char priimek[15];
double cas;
char nacionalnost[3];
char ime_ekipe[15];
}t1,t2,t3,t4,t5,t6;
void uredipocasu()//sortbytime/bubblesort
{
int pom;
for(int i = 0; i < 6; i++)//pass 6 times
{
for(int j = 1; j < 5; j++)
{
if(t[j].cas < t[j+1].cas)
{
pom = t[j].sstevilka;
t[j].sstevilka = t[j+1].sstevilka;
t[j+1].sstevilka = pom;
pom = t[j].ime;
t[j].ime = t[j+1].ime;
t[j+1].ime = pom;
pom = t[j].priimek;
t[j].priimek = t[j+1].priimek;
t[j+1].priimek = pom;
pom = t[j].cas;
t[j].cas = t[j+1].cas;
t[j+1].cas = pom;
pom = t[j].nacionalnost;
t[j].nacionalnost = t[j+1].nacionalnost;
t[j+1].nacionalnost = pom;
pom = t[j].ime_ekipe;
t[j].ime_ekipe = t[j+1].ime_ekipe;
t[j+1].ime_ekipe = pom;
}
}
}
}