dont know why my function isn't working, i suspect the while loop triggers even when it shouldn't.
void sort_pairs(void)
{
// TODO
supair supairs[pair_count];
supair unSorted[pair_count];
for (int i = 0; i < pair_count; i++)
{
pair normal = pairs[i];
supair super;
super.toSort = normal;
super.strength = preferences[super.toSort.winner][super.toSort.loser];
super.index = i;
super.propIndex = 0;
supairs[i] = super;
unSorted[i] = super;
}
for (int i = 0; i < pair_count; i++)
{
supair super = unSorted[i];
for (int j = 0; j < pair_count; j++)
{
pair pair2 = pairs[j];
int check = preferences[pair2.winner][pair2.loser];
if (check > super.strength)
{
super.propIndex++;
}
}
while (supairs[super.propIndex].strength == super.strength && super.propIndex != super.index)
{
super.propIndex++;
}
supair placeHolder = supairs[super.propIndex];
supair dup = super;
supairs[super.index] = placeHolder;
placeHolder.index = dup.index;
supairs[super.propIndex] = dup;
dup.index = dup.propIndex;
}
for (int i = 0; i < pair_count; i++)
{
pairs[i] = supairs[i].toSort;
}
return;
}
i also used a new struct:
typedef struct
{
pair toSort;
int strength;
int index;
int propIndex;
}
supair;
anyone know what is wrong?