I am working on a simulation. For this simulation I need 20 nodes (static) and then each node has a queue associated with it. This queue could hold any number of values. What would be the best way to implement 开发者_运维知识库this in C? I was aiming at having each of the queues being a simple linked list, but how can I effectively create several queues, one for each node??
Thanks, Any help would be most appreciated
Basically, you need to create one struct for the queue, which is a simple linked list:
typedef struct queue_t {
int data; /* the date in the queue, can be anything, not only an int */
struct queue_t* next; /* pointer to the next in the queue */
} queue_t;
And then another one is the list of 20 queues:
queue_t *list_of_queues[20];
That's the simplest way to go about it, IMHO.
Edit: Made the array of structs into an array of pointers
精彩评论