stephen
stephen

Reputation: 1

creating a list of queues

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

Upvotes: 0

Views: 743

Answers (1)

Nathan Fellman
Nathan Fellman

Reputation: 127428

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

Upvotes: 2

Related Questions