📄 queue.h
字号:
#ifndef QUEUE_H
#define QUEUE_H
#include <iostream>
#include <iomanip>
using namespace std;
const int MAXSIZE = 100000; //Maximum size of the queue.
const int WIDTH = 5; //Print field size
class Queue
{
friend ostream& operator<< (ostream& out, Queue& Q)
{
for (int n = 0; n < Q.size; n++)
out << setw (WIDTH) << Q.line [n];
return out;
}
public:
Queue ()
{
size = 0;
}
void push (int n)
{
if (size < MAXSIZE)
{
line [size] = n;
size++;
}
}
void pop ()
{
if (size > 0)
{
//Remove the person at the beginning by moving
// everyone else forward one place.
for (int n = 0; n < size - 1; n++)
line [n] = line [n + 1];
size--;
}
}
int getFirstInLine ()
{
//Return a copy of the first person in line.
int temp = -1;
if (size > 0)
temp = line [0];
return temp;
}
bool isEmpty ()
{
return size == 0;
}
private:
int size; //Queue length
int line [MAXSIZE];
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -