Home > Back-end >  Bosses to help take a look at the stack and queue type definition
Bosses to help take a look at the stack and queue type definition

Time:09-15

I stack type definition is
Typedef struct stacknote
{
char data;
Struct stacknote * next;
} stacknote, * Linkstackptr;

Typedef struct node
{
Int count;
Linkstackptr top;
} Linkstack;
In the empty stack function dynamically allocated memory format
Void Initstack (Linkstack * s)
{
S=(Linkstack *) malloc (sizeof (Linkstack));
If (* s==NULL)
{
return;
}
The else
{
S - & gt; Top=NULL;
}
}



This is the type of queue format and dynamically allocated memory
Typedef struct queuenote
{
The int data;
Struct queuenote * next;
} queuenote, * Linkqueueptr;

Typedef struct
{
Linkqueueptr front and rear;
} Linkqueue;

Empty
Int Initqueue (Linkqueue * p)
{
P - & gt; The front=p - & gt; Rear=(Linkqueueptr) malloc (sizeof (queuenote));
if(! P - & gt; Front)
{
return 0;
}
P - & gt; The front - & gt; Next=p - & gt; Rear - & gt; Next=NULL;
return 1;
}
Why are two different after I adapt to the format of the stack, set him on the queue results wrong that is why asking bosses parsing,

Finally there is a small problem
Void print (Linkqueue q)
{
While (q.f ront!=q.r ear)
{
Q.f ront=q.f ront - & gt; next;//note that front points to head nodes of the first is to point to the next
Printf (" % d \ n ", q.f ront - & gt; The data);
}
} in the print queue is why q.f ront instead of q - & gt; The front
The two have what difference

CodePudding user response:

Look at the building Lord Linkqueue is the structure types or structure pointer type, typedef Linkqueue front did not *.
So Linkqueue q; Is the structure of variables, so use. No - & gt;

CodePudding user response:

After stack is advanced, only need a stack, pressure from the stack and the stack; Queues are first in first out, read his head and tail to write
  • Related