SHARE
TWEET

Untitled

a guest Apr 24th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include "Sort.h"
  3. 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))
  4. {
  5.     system("cls");
  6.     cout << "ïî êàêîìó ïîëþ ñîðòèðîâàòü:" << endl;
  7.     cout << "1-íîìåð" << endl//+
  8.         << "2-èìÿ" << endl//+
  9.         << "3-ôàìèëèÿ" << endl//+
  10.         << "4-îò÷åñòâî" << endl//+
  11.         << "5-ãîä ðîæäåíèÿ" << endl//+
  12.         << "Ìåñòî æèòåëüñòâà" << endl//+
  13.         <<"6-ãîðîä"<<endl//+
  14.         <<"7-óëèöà"<<endl//+
  15.         << "8-íàëè÷èå áðàêà" << endl//+
  16.         << "9-ìåñòî ðàáîòû" << endl//+
  17.         << "10-íàëè÷èå ñóäèìîñòåé" << endl//+
  18.         << "11-ïðîõîæäåíèå ñëóæáû â àðìèè" << endl;//+
  19.     int n = getSize(head);
  20.     P_BASE *people_1 = new P_BASE[n];
  21.     people_1 = ToStruct(head);
  22.     switch (_getch())
  23.     {
  24.     case '1': {
  25.         for (int i = 0; i < n - 1; i++) {
  26.             for (int j = i + 1; j < n; j++) {
  27.                 people_1=sortint(people_1, i, j, people_1[i].number, people_1[j].number);
  28.             }
  29.         }
  30.         break;
  31.     }
  32.     case '2': {
  33.         for (int i = 0; i < n - 1; i++) {
  34.             for (int j = i + 1; j < n; j++) {
  35.                 people_1 = sortchar(people_1, i, j, people_1[i].name, people_1[j].name);
  36.             }
  37.         }
  38.    
  39.         break;
  40.     }
  41.     case '3': {
  42.         for (int i = 0; i < n - 1; i++) {
  43.             for (int j = i + 1; j < n; j++) {
  44.                 people_1 = sortchar(people_1, i, j, people_1[i].l_name, people_1[j].l_name);
  45.             }
  46.         }
  47.        
  48.         break;
  49.     }
  50.     case '4': {
  51.         for (int i = 0; i < n - 1; i++) {
  52.             for (int j = i + 1; j < n; j++) {
  53.                 people_1 = sortchar(people_1, i, j, people_1[i].f_name, people_1[j].f_name);
  54.             }
  55.         }
  56.        
  57.         break;
  58.     }
  59.     case '5': {
  60.         for (int i = 0; i < n - 1; i++) {
  61.             for (int j = i + 1; j < n; j++) {
  62.                 people_1 = sortint(people_1, i, j, people_1[i].date, people_1[j].date);
  63.             }
  64.         }
  65.    
  66.         break;
  67.     }
  68.     case '6': {
  69.         for (int i = 0; i < n - 1; i++) {
  70.             for (int j = i + 1; j < n; j++) {
  71.                 people_1 = sortchar(people_1, i, j, people_1[i].h_town.city, people_1[j].h_town.city);
  72.             }
  73.         }
  74.        
  75.         break;
  76.     }
  77.     case '7': {
  78.         for (int i = 0; i < n - 1; i++) {
  79.             for (int j = i + 1; j < n; j++) {
  80.                 people_1 = sortchar(people_1, i, j, people_1[i].h_town.st, people_1[j].h_town.st);
  81.             }
  82.         }
  83.  
  84.         break;
  85.     }
  86.     case '8': {
  87.         for (int i = 0; i < n - 1; i++) {
  88.             for (int j = i + 1; j < n; j++) {
  89.                 people_1 = sortchar(people_1, i, j, people_1[i].mary, people_1[j].mary)
  90.                     ;
  91.             }
  92.         }
  93.        
  94.         break;
  95.     }
  96.     case '9': {
  97.         for (int i = 0; i < n - 1; i++) {
  98.             for (int j = i + 1; j < n; j++) {
  99.                 people_1 = sortchar(people_1, i, j, people_1[i].work_p, people_1[j].work_p);
  100.             }
  101.         }
  102.        
  103.        
  104.        
  105.         break;
  106.     }
  107.     case '10': {
  108.         for (int i = 0; i < n - 1; i++) {
  109.             for (int j = i + 1; j < n; j++) {
  110.                 people_1 = sortchar(people_1, i, j, people_1[i].jail, people_1[j].jail)
  111.                     ;
  112.             }
  113.         }
  114.  
  115.         break;
  116.     }
  117.     case '11': {
  118.         for (int i = 0; i < n - 1; i++) {
  119.             for (int j = i + 1; j < n; j++) {
  120.                 people_1 = sortchar(people_1, i, j, people_1[i].army, people_1[j].army)
  121.                     ;
  122.             }
  123.         }
  124.  
  125.         break;
  126.     }
  127.                 default: {
  128.     cout << "ââåäåíî íåêîððåêòíîå çíà÷åíèå "<<endl;     
  129.         return head;
  130.         break;
  131.     }
  132.     }
  133.    
  134.  
  135.     cout << "âûáåðèòå ïîðÿäîê ñîðòèðîâêè(1-ïðÿìîé, 2-îáðàòíûé)"<<endl;
  136.         switch (_getch())
  137.         {
  138.         case '1': {
  139.                 head = Clear(head);
  140.             for (int i = 0; i < n; i++) {
  141.                 push(&head, people_1[i]);
  142.             }
  143.             break;
  144.         }
  145.         case '2': {
  146.                 head = Clear(head);
  147.             for (int i = n - 1; i >= 0; i--) {
  148.                 push(&head, people_1[i]);
  149.             }
  150.             break;
  151.         }
  152.         }
  153.        
  154.  
  155.     return head;
  156. }
  157.  
  158. P_BASE * CharSort(P_BASE *people_1, int i, int j,char *buff1,char *buff2) {
  159.     if (strcmp(buff1, buff2) < 0)
  160.     {
  161.         P_BASE *p = (P_BASE*)calloc(1, sizeof(P_BASE));
  162.         p[0] = people_1[i];
  163.         people_1[i] = people_1[j];
  164.         people_1[j] = p[0];
  165.         _freea(p);
  166.     }
  167.     return people_1;
  168. }
  169.  
  170. P_BASE * IntSort(P_BASE *people_1, int i, int j, int a,int b) {
  171.     if (b>a)
  172.     {
  173.         P_BASE *p = (P_BASE*)calloc(1, sizeof(P_BASE));
  174.         p[0] = people_1[i];
  175.         people_1[i] = people_1[j];
  176.         people_1[j] = p[0];
  177.         _freea(p);
  178.     }
  179.     return people_1;
  180. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top