Răspuns :
#include <iostream>
using namespace std;
//Definitii structuri
struct Data {
int an, luna, zi;
};
struct Elev {
char nume[50];
int clasa;
Data data_nasterii;
};
//Definitii comparatoare
bool comp_data(Data d1, Data d2) {
if (d1.an < d2.an)return 1;
if (d1.luna < d2.luna)return 1;
if (d1.zi < d2.zi) return 1;
return 0;
}
bool comp_elevi_dn(Elev e1, Elev e2) {
return comp_data(e1.data_nasterii, e2.data_nasterii);
}
//Sortare QuickSort
void quickSort(Elev arr[], int left, int right, bool (*comp)(Elev, Elev)) {
int i = left, j = right;
int tmp;
Elev pivot = arr[(left + right) / 2];
/* Partitionare */
while (i <= j) {
while (comp(arr[i],pivot))
i++;
while (comp(pivot,arr[j]))
j--;
if (i <= j) {
swap(arr[i], arr[j]);
i++;
j--;
}
};
/* Recursivitate */
if (left < j)
quickSort(arr, left, j, comp);
if (i < right)
quickSort(arr, i, right, comp);
}
Elev* citire_date(int dim) {
Elev* arr = new Elev[dim];
for (int index = 0; index < dim; index++) {
cout << "\nElev #" << index << endl;
cout << "\tNume : ", cin >> arr[index].nume;
cout << "\tClasa : ", cin >> arr[index].clasa;
cout << "\tData nasterii (ZI LUNA AN) : ", cin >> arr[index].data_nasterii.zi >> arr[index].data_nasterii.luna >> arr[index].data_nasterii.an;
}
return arr;
}
void afisare_elevi(Elev* arr, int dim) {
for (int index = 0; index < dim; index++) {
cout << "\nElev #" << index;
cout << "\n\tNume : " << arr[index].nume;
cout << "\n\tClasa : " << arr[index].clasa;
cout << "\n\tData nasterii : " << arr[index].data_nasterii.an << " " << arr[index].data_nasterii.luna << " " << arr[index].data_nasterii.zi;
}
}
int main() {
int dim = 3;
Elev *arr = citire_date(dim);
quickSort(arr, 0, dim - 1, comp_elevi_dn);
cout << "\n=============\n";
afisare_elevi(arr, dim);
}