📄 队列.cpp
字号:
template<class Type>
class Queue
{
public:
Type *H;
int Capacity;
int Size;
int Front;
int Rear;
public:
Queue(int n)
{
H = NULL;
H = new Type[n+1];
Capacity = n;
Size = 0;
Front = 0;
Rear = 0;
};
Queue( Queue& a )
{
//要排除自赋值的情况
if ( this.H != a.H )
{
this.H = a.H;
this.Size = a.Size;
this.Capacity = a.Capacity;
this.Front = a.Front;
this.Rear = a.Rear;
for( int i = 0; i < Size; ++i )
{
this.H[i] = a.H[i];
}
}
};
void Add( Type& node )
{
if ( Size == Capacity )
{
cout<<"capacity"<<endl;
return;
}
else
{
//cout<<"Add type:"<<endl;
if ( Rear + 1 == Capacity )
{
H[Rear] = node;
Rear = 0;
++Size;
}
else
{
H[Rear] = node;
++Size;
++Rear;
}
//cout<<"Size = "<<Size<<endl;
//cout<<"Rear = "<<Rear<<endl;
}
};
void Delete( Type& node )
{
if ( Size == 0 )
{
return;
}
else
{
//cout<<"Delete:"<<endl;
if ( Front == Capacity )
{
Front = 0;
}
node = H[Front];
//cout<<"node:"<<endl;
++Front;
--Size;
}
//cout<<"Size = "<<Size<<endl;
//cout<<"Front = "<<Front<<endl;
};
bool IsEmpty()
{
return ( 0 == Size );
};
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -