📄 queue.cpp
字号:
// Queue.cpp: implementation of the CQueue class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "BFSearch.h"
#include "Queue.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CQueue::CQueue(int sz) // Constructor
{
// Make list array one position larger for empty slot
size = sz + 1;
rear = 0;
front = 1;
listArray = new int[size];
}
CQueue::~CQueue()
{
delete [] listArray;
}
void CQueue::clear()
{
front = rear;
}
bool CQueue::enqueue(int &it)
{
if (((rear+2) % size) == front)
return false; // Full
rear = (rear+1) % size; // Circular increment
listArray[rear] = it;
return true;
}
bool CQueue::dequeue(int &it)
{
if (length() == 0) return false; // Empty
it = listArray[front];
front = (front+1) % size; // Circular increment
return true;
}
bool CQueue::frontValue(int &it)
{
if (length() == 0)
return false; // Empty
it = listArray[front];
return true;
}
int CQueue::length()
{
return ((rear+size) - front + 1) % size;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -