I've been at this for several hours and I'm still very confused. I'm trying to make a sorting function using a pointer that's pointing at a struct called Student. I'm still a bit new with pointers, so I'm not completely sure if my code is correct. I figured it should be able to swap the student's scores in ascending order with temp, since that works just fine with everything. Except pointers, anyways. Wouldn't it be (students + i)->score = (students + j->score and vice versa to swap the two?
#include <iostream>
#include <string>
using namespace std;
struct Student
{
string name;
int score;
};
void sortScores(Student* students, int numStudents)
{
int temp;
for (int i = 0; i < numStudents; i++)
{
for (int j = i + 1; i < numStudents; j++)
{
if ((students + j)->score < (students + i)->score)
{
temp = (students + i)->score;
(students + i)->score = (students + j)->score;
(students + j)->score = (students + temp)->score;
}
}
}
}```