2 years ago

#71132

test-img

cs_student

Circular (priority) queue in C

I have found following code for a circular queue (probably). But I can't understand function circ_queue_getFirst. As I see the code initialises struct. Then we can append (not shown) up to 5 elements, first one will be head, last one tail. Why is there tail then mentioned, if it should return first member?

typedef struct CircularQueue
{
    uint8_t size;
    
    uint8_t head;

    uint8_t tail;
    
    Data data[5];

} CircularQueue ;
void circ_queue_init (CircularQueue *queue){
    queue->head = 0;
    queue->tail = 0;
    queue->size = 5;
}
Data circ_queue_getFirst(CircularQueue *queue){
    return queue->data[queue->tail];
}

arrays

c

queue

priority-queue

0 Answers

Your Answer

Accepted video resources