Home > Back-end >  Consult each great god queue problem, appreciated
Consult each great god queue problem, appreciated

Time:10-02

#include
using namespace std;
Typedef struct node {
int data;
Node * next;
} the node;
The class queue {
Public:
The queue ();
~ the queue ();
Bool empty () const;
Bool full () const;
Int get_front (int& X) const;
Int append (const int x);
Int serve ();
Void the show ();
Private:
int count;
Node * rear;
Node * front;
};
Queue: : queue () {
The front=new node;
Rear=front;
The front - & gt; Next=NULL;
Count=0;
Cout & lt; <"The queue sucess \ n";
}
Queue: : ~ queue () {
while (! The empty ()) serve ();
Delete the front;
Cout & lt; <"~ sucess \ n";
}
Bool queue: : empty () const {
Return the count==0;
}
Bool queue: : full () const {
return false;
}
Int the queue: : get_front (int& X) const {
Return false if (empty ());
X=front - & gt; Next - & gt; The data;
Cout & lt; return true;
}

Int the queue: : append (const int x) {
Return false if (full ());
Node * s=new node;
S - & gt; Data=https://bbs.csdn.net/topics/x;
S - & gt; Next=NULL;
Rear - & gt; Next=s;
Count++;
Cout & lt; <"Append success \ n";
return true;
}
Int the queue: : serve () {
Return false if (empty ());
The node * u;
Cout & lt; <"Yes \ n";
U=front - & gt; Next;
The front - & gt; Next=u - & gt; Next;
The delete u;
count--;
If (front - & gt; Next==NULL) rear=front;
return true;
}
Void queue: : show () {
Cout & lt; }
Int main () {
The queue q;
Int x;
For (int I=0; I & lt; 10; I++) {
Q.a ppend (I);
}
For (int I=0; I & lt; 10; I++) {
Q.s erve ();
}
return 0;
}
When the team will be the problem of u is a null pointer
  • Related