📄 04020.cpp
字号:
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
template <class T>
class Queue{
public:
Queue() {front=rear=0;}
~Queue();
bool Empty() const
{
return ((front)?false:true);
}
bool Full() const;
T First() const;
T Last() const;
Queue<T> & EnQueue(const T& x);
Queue<T> & DeQueue(T& x);
void Exchange(int,int);
int size();
struct Node
{
T data;
Node *next;
};
Node *front; //队首结点指针
Node *rear; //队尾结点指针
};
template<class T>
Queue<T>::~Queue()
{
Node *next;
while(front)
{
next=front->next;
delete front;
front=next;
}
}
template<class T>
bool Queue<T>::Full() const
{
Node *p;
try
{
p=new Node;
delete p;
return false;
}
catch(it is wrong)
{
return true;
}
}
template<class T>
T Queue<T>::First() const
{
if(Empty()) cout<<"it is wrong";
return front->data;
}
template<class T>
T Queue<T>::Last() const
{
if(Empty()) out<<"it is wrong";
return rear->data;
}
template<class T>
Queue<T> & Queue<T>::EnQueue(const T& x)
{ //创建一个新结点
Node *p=new Node;
p->data=x;
p->next=0;
//在队尾插入新结点
if(front) rear->next=p; //队列非空
else front=p;//空队列
rear=p;
return *this;
}
template<class T>
Queue<T> & Queue<T>::DeQueue(T& x)
{
if(Empty()) cout<<"it is wrong";
//将队首元素存于X中
x=front->data;
//删除队首结点
Node *p=front;
front=front->next;
delete p;
return *this;
}
int main()
{
ifstream in("input.txt");
if(in.fail())
{
cout<<"the input.txt is not exist";
exit(1);
}
ofstream out("output.txt");
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -