Home > Back-end >  Bosses help see where is wrong
Bosses help see where is wrong

Time:04-03

# include
# include
# define OVERLOW - 2
# define the ERROR 0
# define OK 1
Typedef int the Status;
Typedef float QElemType;
Typedef struct QLNode {
QElemType data;
Struct QLNode * next;
} QLNode, * QueuePtr;
Typedef struct {
QueuePtr front;
QueuePtr rear;
} LinkQueue;
//create an empty queue
The Status InitQueue (LinkQueue & amp; Q)
{
Q.f ront=Q.r ear=(QueuePtr) malloc (sizeof (QLNode));
if(! Q.f ront)
{
The exit (OVERLOW);
}
Q.f ront=NULL;
Return OK;
}
//destruction of queue
The Status DestoryQueue (LinkQueue & amp; Q)
{
While (Q.f ront)
{
Q.r ear=Q.f ront - & gt; Next;
Free (Q.r ear);
Q.f ront=Q.r ear;
}
Return OK;
}
//insert element for Q e new elements of the
The Status the EnQueue (LinkQueue & amp; Q, QElemType e)
{
QueuePtr p;
Printf (" please input the value of e \ n ");
The scanf (" % f ", & amp; e);
P=(QueuePtr) malloc (sizeof (QLNode));
if(! P)
{
The exit (OVERLOW);
}
P - & gt; Data=https://bbs.csdn.net/topics/e;
P - & gt; Next=NULL;
Q.r ear - & gt; Next=p;
Q.r ear=p;
Return OK;
}
//delete an opponent of the Q elements, e back to
The Status to DeQueue (LinkQueue & amp; Q, QElemType & amp; E)
{
QueuePtr p;
P=(QueuePtr) malloc (sizeof (QLNode));
if(! P)
{
The exit (OVERLOW);
}
If (Q.f ront==Q.r ear)
{
return ERROR;
}
P=Q.f ront - & gt; Next;
E=p - & gt; The data;
Q.f ront - & gt; Next=p - & gt; Next;
If (p==Q.r ear)//when deletes the last element, the tail pointer might not point to
{
Q.r ear=Q.f ront;
}
Free (p);
Return OK;
}
//to empty queue
The Status ClearQueue (LinkQueue & amp; Q)
{
QueuePtr p;
P=(QueuePtr) malloc (sizeof (QLNode));
if(! P)
{
The exit (OVERLOW);
}
while(! Q.r ear)
{
P=Q.f ront - & gt; Next;
Q.f ront - & gt; Next=p - & gt; Next;
Free (p);
}
Q.r ear=Q.f ront;
Return OK;
}
//calculate the length of queue
The Status QueueLength (LinkQueue Q)
{
QueuePtr p;
P=(QueuePtr) malloc (sizeof (QLNode));
if(! P)
{
The exit (OVERLOW);
}
The Status I=1;
P=Q.f ront - & gt; Next;
while(p !=Q.r ear)
{
P=p - & gt; Next;
i++;
}
return i;
}
//by the head of the e return Q element
The Status GetHead (LinkQueue Q, QElemType & amp; E)
{
If (Q.f ront==Q.r ear)
{
return ERROR;
}
E=Q.f ront - & gt; Next - & gt; The data;
Return OK;
}
//display the queue
The Status VisitQueue (LinkQueue Q)
{
QueuePtr p;
P=(QueuePtr) malloc (sizeof (QLNode));
if(! P)
{
The exit (OVERLOW);
}
P=Q.f ront - & gt; Next;
while(p !=Q.r ear - & gt; Next)
{
Printf (" % f ", p - & gt; The data);
P=p - & gt; Next;
}
return 0;
}
Int main ()
{
LinkQueue Q;
QElemType e;
The Status flag.
While (1)
{
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" * * * * * * * * queue operating system * * * * * * * * \ n ");
Printf (" 1. Create an empty queue \ n ");
Printf (" (2) insert element for Q e new elements of the \ n ");
Printf (" 3. Delete an opponent of the Q elements, use e back to \ n ");
Printf (" 4. Empty the queue \ n ");
Printf (" 5. Calculating the length of queue \ n ");
Printf (" 6. By the head of the e return Q element \ n ");
Printf (" 7. According to queue \ n ");
Printf (" 8. Destroy the queue \ n ");
Printf (" please select a function number: \ n ");
The scanf (" % d ", & amp; The flag);
The switch (flag)
{
Case 1: InitQueue (Q);
break;
Case 2: the EnQueue (Q, e);
break;
Case 3: to DeQueue (Q, e);
break;
Case 4: ClearQueue (Q);
break;
Case 5: QueueLength (Q);
break;
Case 6: GetHead (Q, e);
break;
Case 7: VisitQueue (Q);
break;
Case 8: DestoryQueue (Q);
break;
}//switch
}//while
Return OK;
}

CodePudding user response:

 # include 
# include

# define OVERLOW - 2
# define the ERROR 0
# define OK 1

Typedef int the Status;
Typedef float QElemType;

Typedef struct QLNode {
QElemType data;
Struct QLNode * next;
} QLNode, * QueuePtr;
Typedef struct {
QueuePtr front;
QueuePtr rear;
} LinkQueue;

//create an empty queue
The Status InitQueue (LinkQueue & amp; Q)
{
/*
Q.f ront=Q.r ear=(QueuePtr) malloc (sizeof (QLNode));
if(! Q.f ront)
{
The exit (OVERLOW);
}

//Q.f ront=NULL;
Q.f ront - & gt; Next=NULL;
*/
Q.f ront=Q.r ear=NULL;
Return OK;
}
The Status ClearQueue (LinkQueue & amp; Q);
//destruction of queue
The Status DestoryQueue (LinkQueue & amp; Q)
{
ClearQueue (Q);
/*
While (Q.f ront)
{
Q.r ear=Q.f ront - & gt; Next;
Free (Q.r ear);
Q.f ront=Q.r ear;
}
*/
Return OK;
}
//insert element for Q e new elements of the
The Status the EnQueue (LinkQueue & amp; Q, QElemType e)
{
QueuePtr p;
Printf (" please input the value of e \ n ");
The scanf (" % f ", & amp; e);
P=(QueuePtr) malloc (sizeof (QLNode));
if(! P)
{
The exit (OVERLOW);
}
P - & gt; Data=https://bbs.csdn.net/topics/e;
P - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related