Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- typedef struct {
- string SNP; //s-фамилия n-имя p-отчество
- int bd, bm, by;//bd-число bm-месяц by-год рождения
- }student;
- /*int comp(const void *a, const void *b) {
- if (((student*)a)->by < ((student*)b)->by)
- return -1;
- else if (((student*)a)->by > ((student*)b)->by)
- return 1;
- else {
- if (((student*)a)->bm < ((student*)b)->bm)
- return -1;
- else if (((student*)a)->bm > ((student*)b)->bm)
- return 1;
- else {
- if (((student*)a)->bd < ((student*)b)->bd)
- return -1;
- else if (((student*)a)->bd > ((student*)b)->bd)
- return 1;
- else
- return 0;
- }
- }
- }*/
- int comp(student a, student b) {
- if (a.by < b.by)
- return -1;
- else if (a.by > b.by)
- return 1;
- else {
- if (a.bm < b.bm)
- return -1;
- else if (a.bm > b.bm)
- return 1;
- else {
- if (a.bd < b.bd)
- return -1;
- else if (a.bd > b.bd)
- return 1;
- else
- return 0;
- }
- }
- }
- void BSort(student *arr, int D, int (*comp)(student a, student b))
- {
- for (int i = 0; i < D; ++i)
- for (int j = i; j > 0 && (comp(arr[j], arr[j - 1]) == -1); --j) //arr[j] < arr[j - 1]
- {
- student temp = arr[j];
- arr[j] = arr[j - 1];
- arr[j - 1] = temp;
- }
- }
- /*
- Составить список студентов группы, включив следующие данные: Ф.И.О.,
- число, месяц и год рождения. Переставить записи студентов по возрасту
- */
- int main()
- {
- student ISP[5] =
- {
- {"Golovin Semen D.",13,2,2002},
- {"Starikov Kirill M.",12,8,2002},
- {"Rubanov Michael D.",4,5,2002},
- {"Nikitin Maksim K.",18,11,2002},
- {"Molodchikov Sergey S.",8,7,2002}
- };
- cout << "old" << endl;
- for (int i = 0; i < 5; i++)
- {
- cout << ISP[i].SNP << " " << ISP[i].bd << "." << ISP[i].bm << "." << ISP[i].by << endl;
- }
- BSort(ISP, 5, comp);
- cout << "\n" << "new" << endl;
- for (int i = 0; i < 5; i++)
- {
- cout << ISP[i].SNP << " " << ISP[i].bd << "." << ISP[i].bm << "." << ISP[i].by << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement