First time writing in C + +, novice, laughed at
#include <iostream.h>
#include <iostream>
Template<typename t>
Class Queue
{
Private
int maxsize,front,rear;
T *q;
Public
Queue ()
{
Q=new T[maxsize];
rear=front=0;
}
~queue ()
{
delete []q;
}
BOOL ADDQ (T item);
BOOL Delete (T &item);
BOOL QFull ();
BOOL Qempty ();
int GetSize ();
};
Template<typename t>
BOOL Queue<t>:: ADDQ (T Item)
{
Rear= (++rear)%maxsize;
if (Rear==front)
{
printf ("The Queue is full");
if (!front)
{
Rear=maxsize;
}
Else
{
Rear=rear-1;
}
return false;
}
Else
{
Q[rear]=item;
return true;
}
}
Template<typename t>
BOOL Queue<t>::D elete (T &item)
{
if (front==rear)
{
printf ("The queue is empty!");
return false;
}
Else
{
front=front+1;
Front=front%maxsize;
Item=q[front];
return true;
}
}
Template<typename t>
int queue<t>:: GetSize ()
{
return rear-front;
}
1, first of all, the class should be written in the. h file
2, the next should write the same as the class name of the constructor
Queue ()
{
Q=new T[maxsize];
rear=front=0;
}
3, Template<typename t>
That way, you don't have to limit the type of data you're using.
4, class after the {} should be added;
5.
BOOL ADDQ (T item);
BOOL Delete (T &item);
BOOL QFull ();
BOOL Qempty ();
int GetSize ();
When writing these functions out of class, you should add template<typename to each function before t>
6, there is another problem:
Delete (T &item)
ADD (T Item)
Why a FETCH address why another does not take address
Try it, it's like two can run for a while.
Some issues to be aware of in C + + queues