⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue.cpp

📁 一个比较详细的操作系统进程同步模拟的例子
💻 CPP
字号:
// Queue.cpp: implementation of the CQueue class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PROCESS.h"
#include "Queue.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

//初始化
CQueue::CQueue():front(0),rear(0),count(0)
{

}

CQueue::~CQueue()
{

}
//入队
void CQueue::QInsert(struct PCB *item)
{
    //若队列已满,则显示出错信息并退出程序
	if(count==MaxSize)
		AfxMessageBox("队列已满,不能插入!");
	else
	{
		//count加1,将元素加入qList,并修改rear值
		count++;
		qList[rear]=item;
		rear=(rear+1)%MaxSize;
	}
}
//出队
struct PCB * CQueue::QDelete()
{  
   if(count==0)//若队列已空,则显示出错信息并退出程序
	   return NULL;
       //AfxMessageBox("队列已空,不能出队!");
   else
   { 
	   //元素个数减1,前移首指针,并返回原队首值
	   struct PCB * temp;
       temp=qList[front];
	   count--;
	   front=(front+1)%MaxSize;
	   return temp;
   }
   
}
//返回队列元素个数
int CQueue::QLength()
{
    return count;
}
//判断队列是否为空
int CQueue::QEmpty()
{
    return count==0;
}
//判断队列是否已满
int CQueue::QFull()
{
    return count==MaxSize;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -