init
This commit is contained in:
50
examples/p_queue_example.c
Normal file
50
examples/p_queue_example.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "p_queue.h"
|
||||
|
||||
DEFINE_QUEUE(int);
|
||||
|
||||
#define SIZE_QUEUE (256)
|
||||
|
||||
queue_int_t queue;
|
||||
int buffer[SIZE_QUEUE];
|
||||
|
||||
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)
|
||||
{
|
||||
queue_int_init(&queue, buffer, SIZE_QUEUE);
|
||||
|
||||
// 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);
|
||||
}
|
||||
Reference in New Issue
Block a user