Home > Back-end >  List pointer
List pointer

Time:09-30

#include
using namespace std;

Typedef char DataType.
Typedef struct QueueNode {
DataType data;
QueueNode * next;
};
Typedef struct Queue {
QueueNode * front;
QueueNode * rear;
};


Boolean IsEmpty (a) Queue * {
If (a - & gt; The front==NULL& & A - & gt; Rear==NULL) {
return true;
}
return false;

}
Void addQueueNode (Queue * & amp; A, DataType data) {
QueueNode * mNode;
If (a - & gt; The front==NULL& & A - & gt; Rear==NULL) {
MNode=new QueueNode;
MNode - & gt; Data=https://bbs.csdn.net/topics/data;
MNode - & gt; Next=NULL;
A - & gt; The front=mNode;
A - & gt; Rear=mNode;
}
The else {
MNode=new QueueNode;
MNode - & gt; Data=https://bbs.csdn.net/topics/data;
MNode - & gt; Next=NULL;
A - & gt; Rear - & gt; Next=mNode;
A - & gt; Rear=mNode;
}
}
DataType deleteQueueNode Queue * (a) {
If (a - & gt; The front==NULL& & A - & gt; Rear==NULL) {
Return NULL;
}
If (a - & gt; The front==a - & gt; Rear) {
DataType mData=https://bbs.csdn.net/topics/a-> front -> data;
QueueNode * MSTR=a - & gt; The front;
A - & gt; The front=NULL;
A - & gt; Rear=NULL;
The delete [] MSTR;
Return mData;
}
The else {
QueueNode * MSTR=a - & gt; The front;
A - & gt; The front=a - & gt; The front - & gt; next;
DataType mData=https://bbs.csdn.net/topics/mstr-> data;
The delete [] MSTR;
Return mData;
}

}

Int main () {


A=new Queue Queue *;
A - & gt; The front==NULL;
A - & gt; Rear==NULL;
AddQueueNode (a, 'a');
AddQueueNode (a, 'B');
AddQueueNode (a, 'B');
Cout & lt; System (" PAUSE ");
return 0;
}
Linked list implementation headless node queue why always an error

CodePudding user response:

What's wrong, where is wrong?
  • Related