#include "card_queue.h" #include void init_queue(struct card_queue *cq) { cq->first = NULL; cq->last = NULL; } void push_queue(struct card_queue *cq, const char *str) { struct card_queue_item *tmp = malloc(sizeof(struct card_queue_item)); tmp->str = str; tmp->next = NULL; if(!cq->first) { cq->first = tmp; cq->last = tmp; } else { cq->last->next = tmp; cq->last = tmp; } } struct card_queue_item* get_next_card_from_queue(struct card_queue *cq, struct card_queue_item *prev) { if(prev == NULL) return cq->first; else return prev->next; } int is_empty_queue(struct card_queue *cq) { return !cq->first; } const char* pop_card_queue(struct card_queue *cq) { struct card_queue_item *tmp = NULL; const char *card = NULL; tmp = cq->first; cq->first = cq->first->next; card = tmp->str; free(tmp); return card; } int find_out_card_quantity_in_cq(const struct card_queue *cq) { int counter = 0; struct card_queue_item *tmp = cq->first; while(tmp) { ++counter; tmp = tmp->next; } return counter; }