Facebook
From Cute Parakeet, 5 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 216
  1. //Zad.7 Usuwanie elementu x
  2. void DelX(node*&H, int x)
  3. {
  4.         if (H != NULL)
  5.         {
  6.                 node*p = H;
  7.                 if (p->next == NULL && p->val == x)
  8.                 {
  9.                         H = NULL;
  10.                         delete p;
  11.                 }
  12.                 while (p->val != x && p != NULL)
  13.                 {
  14.                         p = p->next;
  15.                         if (p->next == NULL && p->val == x)
  16.                         {
  17.                                 node*e = H;
  18.                                 while (e->next->next != NULL)
  19.                                 {
  20.                                         e = e->next;
  21.                                 }
  22.                                 e->next = NULL;
  23.                                 delete p;
  24.                         }
  25.                 }
  26.                 if (p != NULL)
  27.                 {
  28.                         node*e = H;
  29.                         while (e->next != p)
  30.                         {
  31.                                 e = e->next;
  32.                         }
  33.                         e->next = p->next;
  34.                         delete p;
  35.                 }
  36.         }
  37. }