Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.>
- typedef struct {
- int x, y;
- } Point;
- struct el {
- struct el *prev;
- struct el *next;
- Point *p;
- }
- typedef struct el *list;
- // uso di una sentinella
- void insert(list set, Point *p) {
- list last = set->prev;
- list item = (list) malloc(sizeof(struct el));
- item->p = p;
- for (; temp->p != NULL; temp = temp->prev) {
- if (p->x > temp->x || (p->x == temp->x && p->y >= temp->y)) {
- break;
- }
- }
- item->prev = temp;
- item->next = temp->next;
- temp->next->prev = item;
- temp->next = item;
- }
- int distanza(Point *a, Point *b) {
- return sqrt(pow(b->x - a->x, 2)+pow(b->y - a->y, 2))
- }
- void elimina(list set, Point *p, int d) {
- list temp = set->next;
- list x;
- for (; temp->p != NULL; temp = temp->next) {
- if (distanza(temp->p, p) < d) {
- temp->prev->next = temp->next;
- temp->next->prev = temp->prev;
- x = temp;
- temp = temp->prev;
- free(x);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment