Home > Back-end >  Only the tail does not lead the node cycle singly linked lists to store queue output into the stack
Only the tail does not lead the node cycle singly linked lists to store queue output into the stack

Time:09-23

//only the tail does not lead the node cycle singly linked lists to store queue
# include & lt; Stdio. H>
# include & lt; stdlib.h>
# define OK 1
# define the ERROR 0
Typedef int elemtype;
Typedef struct qnode {
Elemtype data;
Struct qnode * next;
} Qnode;


Void the Create (rear) Qnode * {
//Qnode * rear;
//rear=(Qnode *) malloc (sizeof (Qnode));
Rear=NULL;
//return the rear;
}



Void enQuene (Qnode * rear, elemtype e) {
Qnode * q;
Q=(Qnode *) malloc (sizeof (Qnode));
Q - & gt; data=https://bbs.csdn.net/topics/e;
If (rear==NULL) {//a circular linked list
Q - & gt; Next=q;
Rear=q;
}

The else {
Q - & gt; Next=rear - & gt; Next;
Rear - & gt; Next=q;
Rear=q;
}
}

Elemtype deQuene (rear) Qnode * {
Qnode * q; Elemtype e;
Q=rear - & gt; Next - & gt; Next - & gt; Next - & gt; Next;
E=q - & gt; The data;
Rear - & gt; Next=q - & gt; Next;
Free (q);
Return e;
}



Int the empty (rear) Qnode * {
Return (rear==NULL);
}
Void main () {
Qnode rear; Int N, I; Elemtype e;
Printf (" both please enter the number: \ n ");
The scanf (" % d ", & amp; N);
If (N<0) printf (" ERROR!" );
The else {
Create (& amp; Rear);
for(i=0; iPrintf (" please enter the first number: % d \ n ", I + 1);
The scanf (" % d ", & amp; E);
EnQuene (& amp; Rear, e);
}
//if (empty (rear) printf (" queue is empty!" );
//else printf (" queue is empty!" );
for(i=0; iPrintf (" % d ", deQuene (& amp; Rear));
}
}
}
  • Related