#include "queue.h" #include void queue_init(struct queue *q) { q->first = NULL; q->last = NULL; } void queue_push(struct queue *q, const struct coordinates *data) { struct item *new_element = malloc(sizeof(struct item)); new_element->point = *data; new_element->next = NULL; if(!q->first) q->first = q->last = new_element; else { q->last->next = new_element; q->last = q->last->next; } } int empty(const struct queue *q) { return q->first ? 0 : 1; } struct coordinates queue_front(const struct queue *q) { return q->first->point; } void pop(struct queue *q) { struct item *tmp = q->first; q->first = q->first->next; free(tmp); } int equal_points(struct coordinates first_point, struct coordinates second_point) { return first_point.x == second_point.x && first_point.y == second_point.y; } int is_consist_point(const struct queue *q, struct coordinates target_point) { enum { false, true }; struct item *tmp_item = q->first; struct coordinates tmp_point; while(tmp_item != NULL) { tmp_point = tmp_item->point; if(equal_points(tmp_point, target_point)) return true; tmp_item = tmp_item->next; } return false; } void queue_clear(struct queue *q) { struct item *tmp; while(q->first != NULL) { tmp = q->first; q->first = q->first->next; free(tmp); } q->first = NULL; q->last = NULL; }