How do I make several queues? Do I make just one struct and then do this in main:
A = NewQueue();
B = NewQueue();
or is it:
struct queue Q1;
struct queue Q2;
How do I make several queues? Do I make just one struct and then do this in main:
A = NewQueue();
B = NewQueue();
or is it:
struct queue Q1;
struct queue Q2;
You do not have to redefine the struct no, but you do have to declare individual instances.
If "A" has not previously been declared, this is illegal in C:
What datatype are a A and B?Code:A = NewQueue(); B = NewQueue();
Probably you want to do something like this:
Code:struct queue Q1 = NewQueue(); struct queue Q2 = NewQueue();
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
ok, but now it says invalid initializer. Are they supposed to be pointers and am I supposed to allocate space?
That depends on NewQueue() -- if NewQueue() returns a pointer then...use a pointer!
You need to allocate space in NewQueue. I was presuming you've already written it and got it working, since you are discussing multiple queues. If not, how about getting one real queue to work first?
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
This creates a new and space for it right?
struct queue *A = (struct queue*)malloc(sizeof(struct queue));
By the way, these are my structs:
Code:// Stores node of the linked list. struct node { int data; struct node* next; }; // Stores queue. struct queue { struct node* front; struct node* rear; };
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge