Если вы имеете в виду, что сам исходный массив студентов не должен сортироваться, а сортируются лишь массив указателей на исходный массив, то программа, к примеру, может выглядеть следующим образом
#include <iostream>
#include <iterator>
#include <algorithm>
struct Student
{
std::string name;
std::string surname;
int test1;
};
struct SortStudents
{
static bool byName(const Student *first, const Student *second)
{
return first->name < second->name;
}
static bool bySurname(const Student *first, const Student *second)
{
return first->surname < second->surname;
}
static bool byTest(const Student *first, const Student *second)
{
return first->test1 < second->test1;
}
};
std::ostream & operator <<(std::ostream &os, Student &st)
{
return os << st.name << ' ' << st.surname << ' ' << st.test1;
}
int main()
{
Student students[] =
{
{ "A", "YY", 10 },
{ "C", "ZZ", 6 },
{ "B", "XX", 12 }
};
const size_t N = sizeof(students) / sizeof(*students);
Student *pStudents[N];
for (size_t i = 0; i < N; i++) pStudents[i] = &students[i];
std::cout << "Sorted by name" << std::endl;
std::sort(std::begin(pStudents), std::end(pStudents),
SortStudents::byName);
for (auto p : pStudents)
{
std::cout << *p << std::endl;
}
std::cout << "\nSorted by surname" << std::endl;
std::sort(std::begin(pStudents), std::end(pStudents),
SortStudents::bySurname);
for (auto p : pStudents)
{
std::cout << *p << std::endl;
}
std::cout << "\nSorted by tests" << std::endl;
std::sort(std::begin(pStudents), std::end(pStudents),
SortStudents::byTest);
for (auto p : pStudents)
{
std::cout << *p << std::endl;
}
return 0;
}
Вывод программы на консоль
Sorted by name
A YY 10
B XX 12
C ZZ 6
Sorted by surname
B XX 12
A YY 10
C ZZ 6
Sorted by tests
C ZZ 6
A YY 10
B XX 12