Problem: to find the right data structure for the queue:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
int main(int argc, const char *argv[])
{
Queue q;
ch ='A';
for (int k = 0; int k < 4; int k++) {
q.addQ(ch);
ch++;
q.addQ(ch);
ch=q.front();
q.removeQ();
}
return 0;
}
I tried to compile it, but the Queue is undeclared:
$ gcc -o Qu_1 -g q_queue.c
q_queue.c: In function 'main':
q_queue.c:8: error: 'Queue' undeclared (first use in this function)
Question: What is the library for the basic data structures such as the queue in the example?
This looks like a good candidate for the TAILQ_* ?
“man queue” will give more details – there are simple lists, tail queues and circular queues there. Those are the macros that you’d need to bolt on your own structures, not classes of course.
The code for your scenario will look something like this (I should have made the add_to_queue return some code to check for error, and avoid global vars too, but hopefully I would be forgiven in this example):