Home > Back-end >  A queue of the template code as array has some problems
A queue of the template code as array has some problems

Time:09-26

#include
using namespace std;
Template
The class Queue {
Public: Queue (int size=0);
The Queue (const Queue & Q);
Virtual ~ Queue ();
Void In (T, n);
Const T Out ();
Bool Empty () const;
Bool Full () const;
Private: int Max. Front T * and * Tail;
};
Template
Queue : : Queue (int size)
{
Front Tail of==new T [(Max=size) + 1);
}
Template
Queue : : Queue (const Queue & Q)
{
Front=new T [(Max=q.m ax) + 1);
Tail=Front + (int (q.T ail - q.F ront));
For (int I=0; i {
The Front [I]=q.F ront [I];
}
}
Template
Queue : : ~ Queue ()
{
The delete [] Front;
}
Template
Const T Queue : : Out ()
{
If (Tail==Front)
{
Cout & lt; <"Overflow" & lt; return -1;
}
The else
{
Return * (Front++);//return to the team the element
}
}
Template
Void Queue : : n (T) In
{
If (int (Tail - Front) & gt;=Max)
Cout & lt; <"Overflow" & lt; The else * (Tail++)=n;
}
Template
Bool Queue : : Empty () const
{
Return the Front==Tail;
}
Template
Bool Queue : : Full (const)
{
Return int (Tail - Front)==Max;
}
Int main ()
{
Queue Queue1 (10); Queue Queue2 (10);
For (int I=2; i <5; I++)
Queue1. In (I);
For (double I=0; i <8; I++)
Queue2. In (I);
Cout & lt;
}
Finally the output function of entrance Out like the debug to the operation of the Front pointer cannot run normally, bosses, please help to look at

CodePudding user response:

Wrong is a team function
  • Related