Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "Sort.h"
- Node_t *Sort(Node_t *head,P_BASE *(sortchar)(P_BASE *people_1, int i, int j, char *buff1, char *buff2),P_BASE*(sortint)(P_BASE *people_1, int i, int j, int a, int b))
- {
- system("cls");
- cout << "ïî êàêîìó ïîëþ ñîðòèðîâàòü:" << endl;
- cout << "1-íîìåð" << endl//+
- << "2-èìÿ" << endl//+
- << "3-ôàìèëèÿ" << endl//+
- << "4-îò÷åñòâî" << endl//+
- << "5-ãîä ðîæäåíèÿ" << endl//+
- << "Ìåñòî æèòåëüñòâà" << endl//+
- <<"6-ãîðîä"<<endl//+
- <<"7-óëèöà"<<endl//+
- << "8-íàëè÷èå áðàêà" << endl//+
- << "9-ìåñòî ðàáîòû" << endl//+
- << "10-íàëè÷èå ñóäèìîñòåé" << endl//+
- << "11-ïðîõîæäåíèå ñëóæáû â àðìèè" << endl;//+
- int n = getSize(head);
- P_BASE *people_1 = new P_BASE[n];
- people_1 = ToStruct(head);
- switch (_getch())
- {
- case '1': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1=sortint(people_1, i, j, people_1[i].number, people_1[j].number);
- }
- }
- break;
- }
- case '2': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1 = sortchar(people_1, i, j, people_1[i].name, people_1[j].name);
- }
- }
- break;
- }
- case '3': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1 = sortchar(people_1, i, j, people_1[i].l_name, people_1[j].l_name);
- }
- }
- break;
- }
- case '4': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1 = sortchar(people_1, i, j, people_1[i].f_name, people_1[j].f_name);
- }
- }
- break;
- }
- case '5': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1 = sortint(people_1, i, j, people_1[i].date, people_1[j].date);
- }
- }
- break;
- }
- case '6': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1 = sortchar(people_1, i, j, people_1[i].h_town.city, people_1[j].h_town.city);
- }
- }
- break;
- }
- case '7': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1 = sortchar(people_1, i, j, people_1[i].h_town.st, people_1[j].h_town.st);
- }
- }
- break;
- }
- case '8': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1 = sortchar(people_1, i, j, people_1[i].mary, people_1[j].mary)
- ;
- }
- }
- break;
- }
- case '9': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1 = sortchar(people_1, i, j, people_1[i].work_p, people_1[j].work_p);
- }
- }
- break;
- }
- case '10': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1 = sortchar(people_1, i, j, people_1[i].jail, people_1[j].jail)
- ;
- }
- }
- break;
- }
- case '11': {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- people_1 = sortchar(people_1, i, j, people_1[i].army, people_1[j].army)
- ;
- }
- }
- break;
- }
- default: {
- cout << "ââåäåíî íåêîððåêòíîå çíà÷åíèå "<<endl;
- return head;
- break;
- }
- }
- cout << "âûáåðèòå ïîðÿäîê ñîðòèðîâêè(1-ïðÿìîé, 2-îáðàòíûé)"<<endl;
- switch (_getch())
- {
- case '1': {
- head = Clear(head);
- for (int i = 0; i < n; i++) {
- push(&head, people_1[i]);
- }
- break;
- }
- case '2': {
- head = Clear(head);
- for (int i = n - 1; i >= 0; i--) {
- push(&head, people_1[i]);
- }
- break;
- }
- }
- return head;
- }
- P_BASE * CharSort(P_BASE *people_1, int i, int j,char *buff1,char *buff2) {
- if (strcmp(buff1, buff2) < 0)
- {
- P_BASE *p = (P_BASE*)calloc(1, sizeof(P_BASE));
- p[0] = people_1[i];
- people_1[i] = people_1[j];
- people_1[j] = p[0];
- _freea(p);
- }
- return people_1;
- }
- P_BASE * IntSort(P_BASE *people_1, int i, int j, int a,int b) {
- if (b>a)
- {
- P_BASE *p = (P_BASE*)calloc(1, sizeof(P_BASE));
- p[0] = people_1[i];
- people_1[i] = people_1[j];
- people_1[j] = p[0];
- _freea(p);
- }
- return people_1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement