tyrion

punti.c

Feb 12th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.>
  3.  
  4. typedef struct {
  5.     int x, y;
  6. } Point;
  7.  
  8. struct el {
  9.     struct el *prev;
  10.     struct el *next;
  11.     Point *p;
  12.    
  13. }
  14. typedef struct el *list;
  15.  
  16. // uso di una sentinella
  17. void insert(list set, Point *p) {
  18.     list last = set->prev;
  19.     list item = (list) malloc(sizeof(struct el));
  20.     item->p = p;
  21.     for (; temp->p != NULL; temp = temp->prev) {
  22.         if (p->x > temp->x || (p->x == temp->x && p->y >= temp->y)) {
  23.             break;
  24.         }
  25.     }
  26.     item->prev = temp;
  27.     item->next = temp->next;
  28.     temp->next->prev = item;
  29.     temp->next = item;
  30. }
  31.  
  32. int distanza(Point *a, Point *b) {
  33.     return sqrt(pow(b->x - a->x, 2)+pow(b->y - a->y, 2))
  34. }
  35.  
  36. void elimina(list set, Point *p, int d) {
  37.     list temp = set->next;
  38.     list x;
  39.     for (; temp->p != NULL; temp = temp->next) {
  40.         if (distanza(temp->p, p) < d) {
  41.             temp->prev->next = temp->next;
  42.             temp->next->prev = temp->prev;
  43.             x = temp;
  44.             temp = temp->prev;
  45.             free(x);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment