Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. /*Функция сортировки товаров по количеству*/
  2. void SortListQuan(List* First)
  3. {
  4.     List* pointer = First;
  5.     List* Headpointer = First;
  6.     int count = 0, j, tmp;
  7.  
  8.     int* Quan = new int[n];
  9.     for (int i = 0; i < n; i++)
  10.     {
  11.         Quan[i] = pointer->tovar.quantity;
  12.         pointer = pointer->next;
  13.     }
  14.  
  15.     for(int i = 0; i < n - 1; i++)
  16.         for (int j = i + 1; j < n; j++)
  17.         {
  18.             if (Quan[i] == Quan[j])
  19.                 Quan[j] = 0;
  20.         }
  21.  
  22.     for (int i = 0; i < n; i++)
  23.         if (Quan[i] != 0)
  24.             count++;
  25.  
  26.     j = 0;
  27.     int* SortQuan = new int[count];
  28.     for (int i = 0; i < n; i++)
  29.         if (Quan[i] != 0)
  30.         {
  31.             SortQuan[j] = Quan[i];
  32.             j++;
  33.         }
  34.  
  35.     for(int i = 0; i < count; i++)
  36.         for(int j = count - 1; j > i; j--)
  37.             if (SortQuan[j - 1] < SortQuan[j])
  38.             {
  39.                 tmp = SortQuan[j-1];
  40.                 SortQuan[j-1] = SortQuan[j];
  41.                 SortQuan[j] = tmp;
  42.             }
  43.  
  44.     pointer = Headpointer;
  45.  
  46.     cout << "\n\n";
  47.     cout << "Информация о всех товарах\n";
  48.     cout << "\n";
  49.  
  50.     int temp = strlen("Название товара") + 1;
  51.     if (temp < get_max_name(pointer) + 1)
  52.         temp = get_max_name(pointer) + 1;
  53.  
  54.     /*Ячейки-заголовки*/
  55.     cout << "Секция" << ' ';
  56.     cout << setw(temp) << "Название товара" << ' ';
  57.     cout << setw(10) << "Цена" << ' ';
  58.     cout << "Количество" << ' ';
  59.     cout << "Дата изготовления" << ' ';
  60.     cout << "Срок хранения(мес.)" << ' ';
  61.     /*Конец ячеек-заголовков*/
  62.     cout << '\n';
  63.  
  64.     pointer = Headpointer;
  65.  
  66.     for (int i = 0; i < count - 1; i++)
  67.     {
  68.         for (int j = 0; j < n; j++)
  69.         {
  70.             if ((pointer->tovar.quantity <= SortQuan[i]) && (pointer->tovar.quantity > SortQuan[i + 1]))
  71.             {
  72.                 cout << setw(6) << pointer->tovar.section << ' ';
  73.                 cout << setw(temp) << pointer->tovar.name << ' ';
  74.                 cout << setw(10) << setprecision(2) << fixed << pointer->tovar.price << ' ';
  75.                 cout << setw(10) << pointer->tovar.quantity << ' ';
  76.                 cout << setw(3) << pointer->tovar.date.day << ' ';
  77.                 cout << setw(8) << pointer->tovar.date.month << ' ';
  78.                 cout << setw(4) << pointer->tovar.date.year << ' ';
  79.                 cout << setw(18) << pointer->tovar.life << ' ';
  80.                 cout << '\n';
  81.             }
  82.             pointer = pointer->next;
  83.         }
  84.         pointer = Headpointer;
  85.     }
  86.  
  87.     for (int j = 0; j < n; j++)
  88.     {
  89.         if ((pointer->tovar.quantity < SortQuan[count-2]) && (pointer->tovar.quantity >= SortQuan[count-1]))
  90.         {
  91.             cout << setw(6) << pointer->tovar.section << ' ';
  92.             cout << setw(temp) << pointer->tovar.name << ' ';
  93.             cout << setw(10) << setprecision(2) << fixed << pointer->tovar.price << ' ';
  94.             cout << setw(10) << pointer->tovar.quantity << ' ';
  95.             cout << setw(3) << pointer->tovar.date.day << ' ';
  96.             cout << setw(8) << pointer->tovar.date.month << ' ';
  97.             cout << setw(4) << pointer->tovar.date.year << ' ';
  98.             cout << setw(18) << pointer->tovar.life << ' ';
  99.             cout << '\n';
  100.         }
  101.         pointer = pointer->next;
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement