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

📄 job.h

📁 一个用于帮助秘书处理公司事务的程序
💻 H
字号:
#include <assert.h>
#include <iostream>
#include <cstdlib>
using namespace std;//预编译命令

char * Person[3]={"Manager","Supervisor","Worker"};//定义字符数组,使输出更直观
const int DefaultPQSize = 50;				//优先级队列数组的默认长度
enum staff{Manager,Supervisor,Worker};

template <class T>
class PQueue
{								//优先级队列的类定义
public:
	PQueue(int sz = DefaultPQSize);			//构造函数
	bool Insert(const T& x);				//将新元素x插入到队尾
	bool RemoveMin(T& x);					//将队头元素删去
	bool getFront(T& x) ; 				//读取队头(具最小优先权)的值
    void makeEmpty() {count = 0;}			//置优先级队列为空
    bool IsEmpty() const					//判队列空否
    {return (count == 0) ? true : false;}			
    bool IsFull() const							//判队列满否
    {return (count == maxSize) ? true : false; }	
    int getSize() const {return count;}	//求优先级队列中元素个数
	void Adjust();		                //调整优先级队列,使优先权从小到大排列
protected:
    T *pqelements;							//优先级队列数组
    int count;								//当前元素个数(长度)
	int maxSize;							//队列最大可容纳元素个数						
}; 

template <class T>
PQueue<T>::PQueue(int sz) : maxSize(sz), count(0)
{
    pqelements = new T[maxSize];			
	assert ( pqelements != NULL );			//断言: 动态存储分配成功与否
}

template <class T>
bool PQueue<T>::Insert(const T& x) 
{
	if (count == maxSize) return false;	//队列满则函数返回
	pqelements[count] = x;  count++;		//插入x到队尾
	Adjust();								//按优先权进行调整
}

template <class T>
void PQueue<T>::Adjust() 
{
	T item = pqelements[count-1];
	int j=0;
	for (j = count-2;  j >= 0;  j--)	
    	if (pqelements[j] < item )
			break;		
		else pqelements[j+1] = pqelements[j];
				//比item大的元素pqelements[j]后移   
   	pqelements[j+1] = item;					//插入到适当位置
}

template <class T>
bool PQueue<T>::RemoveMin(T& x) 
{
	if (count == 0) return false;			//若队列空, 函数返回false
	x = pqelements[0];
	for (int i = 1; i < count; i++)
		pqelements[i-1] = pqelements[i];
	count--;  								//优先级队列元素个数减一
    return true;							//删除成功,返回true
}

template <class T>
bool PQueue<T>::getFront(T &x)
{
	if (count == 0) return false;			//若队列空, 函数返回
	else 
	{ 
		x=pqelements[0];//返回具最小优先权元素的值
		return true;
	}
}

class JobRequest                           //定义类型JobRequest
{
	friend bool operator<(JobRequest &a,JobRequest &b) //定义友元函数,便于优先级的比较
	{
		return a.staffPerson<b.staffPerson;
	}
public:
	staff staffPerson;
	int jobID;
	int jobTime;
	void PrintJobInfo()                           //打印函数,用于打印作业信息
	{    
		cout<<"staffPerson: "<<Person[staffPerson]<<",jobID: "<<jobID<<",jobTime: "<<jobTime<<endl;
	}
};



⌨️ 快捷键说明

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