Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. void DelEnd(node*& H)
  2. {
  3.     if (H != NULL)
  4.     {
  5.         node* P = H;
  6.         if (P->next == NULL)
  7.             DelNode(H);
  8.  
  9.         else
  10.         {
  11.             while (P->next->next != NULL)
  12.                 P = P->next;
  13.             DelNode(P->next);
  14.  
  15.         }
  16.     }
  17. }
  18.  
  19. // Usuń co drugi
  20. void Del2nd(node*& H)
  21. {
  22.     node* P = H;
  23.     while (P && P->next)
  24.     {
  25.         DelNode(P->next);
  26.         P = P->next;
  27.     }
  28. }
  29.  
  30. // Kopiuj parzyste elementy
  31. void CopyEven(node* H)
  32. {
  33.     if (H != NULL)
  34.     {
  35.         node* P = H;
  36.         while (P != NULL)
  37.         {
  38.             if (P->val % 2 == 0)
  39.             {
  40.                 node* q = new node;
  41.                 q->val = P->val;
  42.                 q->next = P->next;
  43.                 P->next = q;
  44.                 P = q->next;
  45.             }
  46.             else
  47.             {
  48.                 P = P->next;
  49.             }
  50.         }
  51.     }
  52. }
  53.  
  54. //12 Zamiana X z nastepnikiem
  55. void ReplaceXandNext(node*& H, int x)
  56. {
  57.     node* P = H;
  58.     if (H->val != x)
  59.     {
  60.         while (P->next != 0 && P->next->val != x)
  61.         {
  62.             P = P->next;
  63.         }
  64.         if (P->next != NULL && P->next->next != NULL)
  65.         {
  66.             node* q = P->next;
  67.  
  68.             P->next = q->next;
  69.             q->next = P->next->next;
  70.             P->next->next = q;
  71.         }
  72.     }
  73.     else
  74.     {
  75.         H = H->next;
  76.         P->next = H->next;
  77.         H->next = P;
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement