You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
838 B
C
51 lines
838 B
C
3 years ago
|
#include "p_queue.h"
|
||
3 years ago
|
|
||
3 years ago
|
DEFINE_QUEUE(int);
|
||
|
|
||
|
#define SIZE_QUEUE (256)
|
||
3 years ago
|
|
||
|
queue_int_t queue;
|
||
3 years ago
|
int buffer[SIZE_QUEUE];
|
||
3 years ago
|
|
||
|
void display(queue_int_t* queue)
|
||
|
{
|
||
|
if (queue->csize == 0)
|
||
|
{
|
||
|
printf("queue is empty\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("Queue:\n");
|
||
|
int i = queue->head;
|
||
|
for (int j = 0; j < queue->csize; j++)
|
||
|
{
|
||
|
printf("[%d]: %d ", i + j, queue->data[(i + j) % queue->msize]);
|
||
|
}
|
||
|
printf("\n");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(int argv, char** argc)
|
||
|
{
|
||
3 years ago
|
queue_int_init(&queue, buffer, SIZE_QUEUE);
|
||
3 years ago
|
|
||
|
// queue.enqueue(&queue, 10);
|
||
|
queue.empty(&queue);
|
||
|
printf("csize: %d\n", queue.csize);
|
||
|
queue.enqueue(&queue, 20);
|
||
|
queue.enqueue(&queue, 30);
|
||
|
queue.enqueue(&queue, 40);
|
||
|
display(&queue);
|
||
|
queue.enqueue(&queue, 10);
|
||
|
|
||
|
int val = 0;
|
||
|
queue.dequeue(&queue, &val);
|
||
|
queue.dequeue(&queue, &val);
|
||
|
|
||
|
display(&queue);
|
||
|
|
||
|
queue.empty(&queue);
|
||
|
|
||
|
display(&queue);
|
||
|
}
|