Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. void vojska(struct DLLNode *lista, int a, int b, int c, int d)
  2. {
  3.     if (lista->Next == lista || lista->Next->Next == lista)
  4.     {
  5.         return;
  6.     }
  7.  
  8.     struct DLLNode *first1 = NULL;
  9.     struct DLLNode *first2 = NULL;
  10.     struct DLLNode *last1 = NULL;
  11.     struct DLLNode *last2 = NULL;
  12.     struct DLLNode *itr1 = lista->Next;
  13.     while (itr1 != lista)
  14.     {
  15.         if (!first1 && itr1->Value == a)
  16.         {
  17.             first1 = itr1;
  18.         }
  19.  
  20.         if (!first2 && itr1->Value == c)
  21.         {
  22.             first2 = itr1;
  23.         }
  24.  
  25.         if (!last1 && itr1->Value == b)
  26.         {
  27.             last1 = itr1;
  28.         }
  29.  
  30.         if (!last2 && itr1->Value == d)
  31.         {
  32.             last2 = itr1;
  33.         }
  34.  
  35.         if (first1 && first2 && last1 && last2)
  36.         {
  37.             break;
  38.         }
  39.  
  40.         itr1 = itr1->Next;
  41.     }
  42.  
  43.     first1->Prev->Next = first2;
  44.     first2->Prev->Next = first1;
  45.     last1->Next->Prev = last2;
  46.     last2->Next->Prev = last1;
  47.  
  48.     itr1 = first1->Prev == first2 ? first1 : first1->Prev;
  49.     first1->Prev = first2->Prev;
  50.     first2->Prev = itr1;
  51.  
  52.     itr1 = last1->Next == last2 ? last1 : last1->Next;
  53.     last1->Next = last2->Next;
  54.     last2->Next = itr1;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement