Advertisement
codegod313

11_2

Jun 28th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. struct St_node
  2. {
  3.     int x;
  4.     St_node* next;
  5. };
  6.  
  7. struct Node
  8. {
  9.     char *s;
  10.     St_node* st;
  11.     Node* next;
  12. };
  13.  
  14. void rewrite_stack(Node* &a)
  15. {
  16.     St_node* current1 = a->next->st;
  17.     St_node* current2 = a->st;
  18.     while (current2 != NULL)
  19.     {
  20.         St_node* tmp = current2->next;
  21.         current2->next = current1;
  22.         current1 = current2;
  23.         current2 = tmp;
  24.     }
  25. }
  26.  
  27. void func(Node* &head)
  28. {
  29.     int max_l = -1;
  30.     Node* max_node = NULL;
  31.     Node* current = head;
  32.     do
  33.     {
  34.         if (strlen(current->s) > max_l)
  35.         {
  36.             max_node = current;
  37.             max_l = strlen(current->s);
  38.         }
  39.     } while (head != current);
  40.     rewrite_stack(max_node);
  41.     current = head;
  42.     while (current->next != max_node)
  43.         current = current->next;
  44.     Node* tmp = max_node->next;
  45.     free(current->next);
  46.     current->next = tmp;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement