Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- struct node
- {
- int info;
- node* next;
- };
- bool nodeIsNull(node*l)
- {
- return(l == NULL);
- }
- void createMas(int mas[])
- {
- for (int i = 0; i < 50; i++)
- mas[i] = rand() % 99 + 1;
- }
- void showMas(int mas[])
- {
- for (int i = 0; i < 50; i++)
- cout << mas[i] << " ";
- }
- void showEl(node*q)
- {
- cout << q->info << " ";
- }
- void setElement(node*&q, node*p)
- {
- q = p;
- }
- void nextEl(node*&q)
- {
- q = q->next;
- }
- void showlist(node* & head)
- {
- node *q = NULL;
- setElement(q, head);
- if (nodeIsNull(q))
- cout << "List Is Empty" << endl;
- else
- while (!nodeIsNull(q))
- {
- showEl(q);
- nextEl(q);
- }
- }
- void newEl(node*&q, int x)
- {
- q = new node;
- q->info = x;
- q->next = NULL;
- }
- void vstavka(node*&head, int x)
- {
- node*q, *p;
- q = head;
- newEl(p, x);
- if (nodeIsNull(head))
- {
- head = p;
- }
- else
- {
- if (x <= head->info)
- {
- p->next = q;
- head = p;
- }
- while (q->next != NULL)
- {
- if (q->info < x && q->next->info >= x)
- {
- p->next = q->next;
- q->next = p;
- }
- nextEl(q);
- }
- if (x >= q->info)
- {
- p->next = NULL;
- q->next = p;
- }
- }
- }
- void svyazkaSpiskov(node**a)
- {
- for (int i = 0; i < 5; i++)
- if (a[i] != NULL)
- {
- cout << "list a[" << i << "] ";
- showlist(a[i]);
- cout << endl;
- }
- }
- void Clear(node**karman)
- {
- for (int i = 0; i < 5; i++)
- karman[i] = NULL;
- }
- void Sortirovka(int *mas, node**karman)
- {
- for (int i = 0; i < 50; i++)
- vstavka(karman[(mas[i] / 20)], mas[i]);
- }
- int main()
- {
- int mas[50];
- node **karman;
- karman = new node *[5];
- Clear(karman);
- createMas(mas);
- showMas(mas);
- cout << endl << endl;
- Sortirovka(mas, karman);
- cout << "New List: ";
- cout << endl;
- svyazkaSpiskov(karman);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment