#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#define LEFT (i-1+PhNum)%PhNum
#define RIGHT i
const int QueueNum=5;//the real Num of the Queue is QueueNum-1
const int PhNum=5;
const int ERROR=0;
const int OK=1;
const int QueuePre=-1;
typedef int ElemType;
//head define....................
/*************************************************************/
class Queue_c
{
ElemType Q[QueueNum];
int front,rear;
public:
//basic information of the class Queue_c:
Queue_c();
int qFull();
int qEmpty();
int qEnQueue(ElemType e);
ElemType qDeQueue();
int qGetNumber();
int qGetElem(int);
int qShowQueue();
//other functions:
//ElemType qGetFrontElem(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return Q[front];}
//int qGetFront(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return front;}
//ElemType qGetRearElem(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return Q[(rear-1+QueueNum)%QueueNum];}
//int qGetRear(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return (rear-1+QueueNum)%QueueNum;}
//int qShowAll();
};
//==================Define of Class Queue_c=====================================
//==============================================================================
class ClopStick_c
{
int e;
public:
ClopStick_c(){e=1;}
int cGetE(){return e;}
void cSTE(){e=1;}
void cCLE(){e=0;}
};
//==================Define of Class ClopStick_c=================================
//==============================================================================
class Philosopher_c
{public:
Queue_c wq;
Queue_c eq;
ClopStick_c cs[PhNum];
public:
int phWait(int);
void phSignal(int);
int phScan(int);
int phWork();
int phShowWq(){return wq.qShowQueue();}
};
//==================Define of Class Philosopher_c=====================================
//==============================================================================
/*******************************==main==****************************************************
********************************==proc==***************************************************/
void main()
{ Philosopher_c ph;
clrscr();
ph.phWork();
//cout<<"scan()="<<ph.phScan(10)<<endl;
//cout<<ph.phWait(0)<<endl;
//ph.phShowWq();
//ph.wq.qEnQueue(2);
//cout<<ph.phScan(2)<<endl;
}
/********************************==END==*****************************************************
*********************************==main==***************************************************/
/************************Class Queue_c**********************************/
//================Queue_c================================
Queue_c::Queue_c()
{
int i;
for(i=0;i<QueueNum;i++)Q[i]=QueuePre;
rear=0;
front=0;
}
//=====================qFull===========================
int Queue_c::qFull()
{
if((rear+1)%QueueNum==front)
{//cout<<"Queue is full"<<endl;
return OK;}
else return ERROR;
}
//================qEmpty================================
int Queue_c::qEmpty()
{
if(rear==front)
#include<stdlib.h>
#include<conio.h>
#define LEFT (i-1+PhNum)%PhNum
#define RIGHT i
const int QueueNum=5;//the real Num of the Queue is QueueNum-1
const int PhNum=5;
const int ERROR=0;
const int OK=1;
const int QueuePre=-1;
typedef int ElemType;
//head define....................
/*************************************************************/
class Queue_c
{
ElemType Q[QueueNum];
int front,rear;
public:
//basic information of the class Queue_c:
Queue_c();
int qFull();
int qEmpty();
int qEnQueue(ElemType e);
ElemType qDeQueue();
int qGetNumber();
int qGetElem(int);
int qShowQueue();
//other functions:
//ElemType qGetFrontElem(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return Q[front];}
//int qGetFront(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return front;}
//ElemType qGetRearElem(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return Q[(rear-1+QueueNum)%QueueNum];}
//int qGetRear(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return (rear-1+QueueNum)%QueueNum;}
//int qShowAll();
};
//==================Define of Class Queue_c=====================================
//==============================================================================
class ClopStick_c
{
int e;
public:
ClopStick_c(){e=1;}
int cGetE(){return e;}
void cSTE(){e=1;}
void cCLE(){e=0;}
};
//==================Define of Class ClopStick_c=================================
//==============================================================================
class Philosopher_c
{public:
Queue_c wq;
Queue_c eq;
ClopStick_c cs[PhNum];
public:
int phWait(int);
void phSignal(int);
int phScan(int);
int phWork();
int phShowWq(){return wq.qShowQueue();}
};
//==================Define of Class Philosopher_c=====================================
//==============================================================================
/*******************************==main==****************************************************
********************************==proc==***************************************************/
void main()
{ Philosopher_c ph;
clrscr();
ph.phWork();
//cout<<"scan()="<<ph.phScan(10)<<endl;
//cout<<ph.phWait(0)<<endl;
//ph.phShowWq();
//ph.wq.qEnQueue(2);
//cout<<ph.phScan(2)<<endl;
}
/********************************==END==*****************************************************
*********************************==main==***************************************************/
/************************Class Queue_c**********************************/
//================Queue_c================================
Queue_c::Queue_c()
{
int i;
for(i=0;i<QueueNum;i++)Q[i]=QueuePre;
rear=0;
front=0;
}
//=====================qFull===========================
int Queue_c::qFull()
{
if((rear+1)%QueueNum==front)
{//cout<<"Queue is full"<<endl;
return OK;}
else return ERROR;
}
//================qEmpty================================
int Queue_c::qEmpty()
{
if(rear==front)