Home > Back-end >  Bosses to help see this code, please why the team is not successful
Bosses to help see this code, please why the team is not successful

Time:06-08

#include
#include
# define TRUE 1
# define FALSE 0
# define OK 1
# define the ERROR 0
# define INFEASIBLE - 1
# define OVERFLOW - 2
typedef int Status;

Typedef struct QNode {
The int data;
Struct QNode * next;
} QNode, * QueuePtr;//queue node type

Typedef struct LinkQueue {
QueuePtr front;
QueuePtr rear;
} LinkQueue;//queue type

The Status Queue_Init (LinkQueue * Q)
{
QNode * head; Head=(QNode *) malloc (sizeof (QNode));
if (! The head) return OVERFLOW;
Q - & gt; The front=Q - & gt; Rear=head;
Q - & gt; The front - & gt; Next=NULL; Return OK;
}

The Status Queue_Destroy (LinkQueue * Q)
{
While (Q - & gt; The front - & gt; Next)
{Q - & gt; Rear=Q - & gt; The front - & gt; Next - & gt; Next; Free (Q - & gt; The front - & gt; Next); Q - & gt; The front - & gt; Next=Q - & gt; The rear;
}
Free (Q - & gt; Front);
Q - & gt; The front=NULL; Return OK;
}

The Status Queue_Clear (LinkQueue * Q)
{
While (Q - & gt; The front - & gt; Next)
{Q - & gt; Rear=Q - & gt; The front - & gt; Next - & gt; Next; Free (Q - & gt; The front - & gt; Next); Q - & gt; The front - & gt; Next=Q - & gt; The rear;
} the Q - & gt; Rear=Q - & gt; The front;
Q - & gt; The front - & gt; Next=NULL; Return OK;
}

The Status Queue_Empty (LinkQueue Q)
{
If (Q.f ront==Q.r ear) return OK;
The else return FALSE;
}

Int Queue_Length (LinkQueue Q)
{
Int length=0; While (Q.f ront - & gt; Next)
{length++; Q.f ront - & gt; Next=Q.f ront - & gt; Next - & gt; Next;
} return length;
}

The Status Queue_Get_First_Element (LinkQueue Q, int * first_element)
{
If (Q.f ront==Q.r ear) return the ERROR;
First_element=& amp; Q.f ront - & gt; Next - & gt; The data; Return OK;
}

The Status Queue_Enter (LinkQueue * Q, int new_element)
{
QNode * new_node; New_node=(QueuePtr) malloc (sizeof (QNode));
if (! New_node) return OVERFLOW;
New_node - & gt; Data=https://bbs.csdn.net/topics/new_element;
New_node - & gt; Next=NULL;
Q - & gt; Rear - & gt; Next=new_node;
Q - & gt; Rear=new_node; Return OK;
}

The Status Queue_Delete (LinkQueue * Q, int * the delete_element)
{
If (Q - & gt; The front==Q - & gt; Rear) return the ERROR;
The delete_element=Q - & gt; The front - & gt; Next - & gt; The data;
Q - & gt; The front - & gt; Next=Q - & gt; The front - & gt; Next - & gt; Next;
If (Q - & gt; The front - & gt; Next==Q - & gt; Q - rear) & gt; Rear=Q - & gt; The front;
Free (Q - & gt; The front - & gt; Next); Return OK;
}

Int main ()
{
The Status function_status;
LinkQueue * LinkQueue;
Int new_element;
Int the delete_element;
Int queue_length=0;
int count=0; Linkqueue=(linkqueue *) malloc (sizeof (linkqueue));
Function_status=Queue_Init (linkqueue);
If (function_status==OK) printf (" \ r \ n initialization chain queue success! \r\n");
If (function_status==OVERFLOW) printf (" \ r \ n initialization chain queue failed! \r\n");
Linkqueue queue_length=queue_length (*);
Printf (" \ r \ n initialization after the success of the chain queue queue length is: % d \ r \ n ", queue_length); Linkqueue function_status=Queue_Empty (*);
If (function_status==OK) printf (" \ r \ n chain queue is empty the queue! \r\n");
If (function_status==ERROR) printf (" \ r \ n chain queue is not empty queue! \r\n");
Linkqueue queue_length=queue_length (*);
Printf (" \ r \ n an empty queue length is: % d \ r \ n ", queue_length); Printf (" \ r \ n please enter the three new plastic elements: ");
For (count=0; The count & lt;=2; Count++)
{the scanf (" % d ", & amp; New_element); Queue_Enter (linkqueue new_element);
Linkqueue} queue_length=queue_length (*);
Printf (" \ r \ n elements after team queue length is: % d \ r \ n ", queue_length); Function_status=Queue_Delete (linkqueue, & amp; The delete_element);
If (function_status==OK) printf (" \ r \ n elements out of team success! \r\n");
If (function_status==ERROR) printf (" \ r \ n elements out team failed! \r\n");
Linkqueue queue_length=queue_length (*);
Printf (" \ r \ n an element after the team queue length is: % d \ r \ n ", queue_length); printf("\n"); return 0;
}

CodePudding user response:

 # include 
#include

# define TRUE 1
# define FALSE 0
# define OK 1
# define the ERROR 0
# define INFEASIBLE - 1
# define OVERFLOW - 2

typedef int Status;

Typedef struct QNode {
The int data;
Struct QNode * next;
} QNode, * QueuePtr;

Typedef struct LinkQueue {
QueuePtr front;
QueuePtr rear;
} LinkQueue;//queue type

The Status Queue_Clear LinkQueue * (Q);


The Status Queue_Init (LinkQueue * Q)
{
QNode * head;
Head=(QNode *) malloc (sizeof (QNode));
if (! The head)
Return OVERFLOW;
Q - & gt; The front=Q - & gt; Rear=head;
Q - & gt; The front - & gt; Next=NULL;
Return OK;
}

The Status Queue_Destroy (LinkQueue * Q)
{
Queue_Clear (Q);

Free (Q - & gt; Front);
Q - & gt; The front=Q - & gt; Rear=NULL;
/*
While (Q - & gt; The front - & gt; Next) {
Q - & gt; Rear=Q - & gt; The front - & gt; Next - & gt; Next;
Free (Q - & gt; The front - & gt; Next);
Q - & gt; The front - & gt; Next=Q - & gt; The rear;
}
Free (Q - & gt; Front);
Q - & gt; The front=NULL;
*/
Return OK;
}

The Status Queue_Clear (LinkQueue * Q)
{

QueuePtr pcur=Q - & gt; The front - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related