Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node
- {
- int x;
- node* y;
- };
- int main()
- {
- node* head = NULL;
- int k = 5;
- head = new node{ rand()%100, NULL };
- head->y = new node{ rand()%100, NULL };
- head->y->y = new node{ rand()%100,NULL };
- head->y->y->y = new node{ rand()%100,NULL };
- head->y->y->y->y = new node{ rand()%100, NULL };
- //head->y = new node{ rand()%100, head->y };
- head->y->y = new node{ -1,head->y->y };
- int d = 0;
- for (node* current = head; current != NULL;current = current->y ) {
- d += current->x;
- }
- node* lessElement = head;
- for (node *current = head, *prev = head,*future=head->y; current != NULL; current = current->y)
- {
- if (current->x < lessElement->x)
- {
- prev->y = future->y;
- lessElement = current;
- }
- }
- for (node* c = head; c != NULL; c = c->y)
- {
- for (node* prev = head, *current = head->y, *next = head->y->y;next->y != NULL; prev = prev->y, current = current->y, next = next->y)
- {
- if (next->x < current->x)
- {
- prev->y = next;
- node* y = next->y;
- next->y = current;
- current->y = y;
- }
- }
- }
- for (node* current = head; current != NULL; current = current->y)
- {
- cout <<"" << current->x << endl;
- }
- std::cout << "The least value is " << lessElement->x << std::endl;
- std::cout << "Value of first node is " << head->x << std::endl;
- std::cout << "Sum of nodes is " << d << std::endl;
- return 0;
- }
- // не сортируется и ничего не выводит на экран
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement