Guest User

Untitled

a guest
Apr 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. void AddGiftToBase(base* to, gift* newgift)
  2. {
  3.     gift* head = to->appended_gifts;
  4.     gift temp = *newgift;
  5.  
  6.     temp.next = NULL; // elkülönítjük a bázishoz csatolt listát, az eredeti listától
  7.     newgift = &temp;
  8.  
  9.     if (head == NULL)
  10.     {
  11.         to->appended_gifts = newgift;
  12.         printf("0\n");
  13.     }
  14.     else
  15.     {
  16.         double currDist = GetDist(head->coord_x, head->coord_y, newgift->coord_x, newgift->coord_y);
  17.         if (GetDist(to->coord_x, to->coord_y, newgift->coord_x, newgift->coord_y) < currDist)
  18.         {
  19.             newgift->next = head;
  20.             head = newgift;
  21.             printf("1, ap: %i, ap: %i; h: %i, h: %i\n", to->appended_gifts->coord_x, to->appended_gifts->coord_y, head->coord_x, head->coord_y);
  22.             return;
  23.         }
  24.  
  25.  
  26.         while (head != NULL && head->next != NULL && (GetDist(head->next->coord_x, head->next->coord_y, newgift->coord_x, newgift->coord_y) < currDist))
  27.         {
  28.             head = head->next;
  29.         }
  30.         newgift->next = head->next;
  31.         head->next = newgift;
  32.        
  33.  
  34.         printf("2, ap: %i, ap: %i; n: %i, n: %i\n", to->appended_gifts->coord_x, to->appended_gifts->coord_y, newgift->coord_x, newgift->coord_y);
  35.     }
  36. }
Add Comment
Please, Sign In to add comment