Aleksandr_Grigoryev

карман

May 7th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1.  
  2. #include<iostream>
  3. #include<fstream>
  4. using namespace std;
  5.  
  6. struct node
  7. {
  8.     int info;
  9.     node* next;
  10. };
  11. bool nodeIsNull(node*l)
  12. {
  13.     return(l == NULL);
  14. }
  15. void createMas(int mas[])
  16. {
  17.     for (int i = 0; i < 50; i++)
  18.         mas[i] = rand() % 99 + 1;
  19. }
  20. void showMas(int mas[])
  21. {
  22.     for (int i = 0; i < 50; i++)
  23.         cout << mas[i] << " ";
  24. }
  25. void showEl(node*q)
  26. {
  27.     cout << q->info << " ";
  28. }
  29. void setElement(node*&q, node*p)
  30. {
  31.     q = p;
  32. }
  33. void nextEl(node*&q)
  34. {
  35.     q = q->next;
  36. }
  37.  
  38. void showlist(node* & head)
  39. {
  40.     node *q = NULL;
  41.     setElement(q, head);
  42.     if (nodeIsNull(q))
  43.         cout << "List Is Empty" << endl;
  44.     else
  45.         while (!nodeIsNull(q))
  46.         {
  47.             showEl(q);
  48.             nextEl(q);
  49.         }
  50. }
  51.  
  52. void newEl(node*&q, int x)
  53. {
  54.     q = new node;
  55.     q->info = x;
  56.     q->next = NULL;
  57. }
  58.  
  59. void vstavka(node*&head, int x)
  60. {
  61.     node*q, *p;
  62.     q = head;
  63.     newEl(p, x);
  64.     if (nodeIsNull(head))
  65.     {
  66.         head = p;
  67.     }
  68.     else
  69.     {
  70.         if (x <= head->info)
  71.         {
  72.             p->next = q;
  73.             head = p;
  74.         }
  75.         while (q->next != NULL)
  76.         {
  77.             if (q->info < x && q->next->info >= x)
  78.             {
  79.                 p->next = q->next;
  80.                 q->next = p;
  81.             }
  82.             nextEl(q);
  83.         }
  84.         if (x >= q->info)
  85.         {
  86.             p->next = NULL;
  87.             q->next = p;
  88.         }
  89.     }
  90. }
  91.  
  92. void svyazkaSpiskov(node**a)
  93. {
  94.     for (int i = 0; i < 5; i++)
  95.         if (a[i] != NULL)
  96.         {
  97.             cout << "list a[" << i << "]  ";
  98.             showlist(a[i]);
  99.             cout << endl;
  100.         }
  101. }
  102.  
  103. void Clear(node**karman)
  104. {
  105.     for (int i = 0; i < 5; i++)
  106.         karman[i] = NULL;
  107. }
  108.  
  109. void Sortirovka(int *mas, node**karman)
  110. {
  111.     for (int i = 0; i < 50; i++)
  112.         vstavka(karman[(mas[i] / 20)], mas[i]);
  113. }
  114.  
  115. int main()
  116. {
  117.     int mas[50];
  118.     node **karman;
  119.     karman = new node *[5];
  120.     Clear(karman);
  121.     createMas(mas);
  122.     showMas(mas);
  123.     cout << endl << endl;
  124.     Sortirovka(mas, karman);
  125.     cout << "New List:  ";
  126.     cout << endl;
  127.     svyazkaSpiskov(karman);
  128.     system("pause");
  129.     return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment