c语言版数据结构-用队列模拟一个银行排号系统的源代码 5
2个回答
展开全部
写个main方法使用循环的方式调用BankSimSystem中的方法即可模拟整个排队和叫号过程。
class BankSimSystem {
private:
QueueManager mQManager;
public:
BankQueueSystem() {
mQManager = new QueueManager();
}
void getOneNum() {
int nRand = random(5);
int nNum;
if nRand <= 2) {
nNum = mQManager.getOneVIPNum();
printf("One people enqueue : N%d" nNum);
} else {
nNum = mQManager.getOneNormalNum();
printf("One people enqueue : V%d" nNum);
}
}
void CallOneNum() {
char *sNum = mQManager.CallOneNum();
if (nNum == -1) {
printf("None in queue");
}
printf("Call the people : %s", sNum);
}
}
class QueueManager {
private:
Queue mNormal;
Queue mVIP;
public:
QueueManager() {
mNormal = new Queue();
mVIP = new Queue();
}
char getOneNormalNum() {
int mNormal.enQueue();
}
int getOneVIPNum() {
return mVip.enQueue();
}
char* CallOneNum() {
char sNum[10];
if (!mVIP.isempty()) {
sprintf(sNum, "V%d",mVIP.outQueue())
return sNum;
}
if (!mNormal.isempty()) {
sprintf(sNum, "N%d",mNormal.outQueue())
return sNum;
}
return null;
}
};
class Queue {
private:
int mNum;
struct Index{
int num;
struct index *next;
} *mHead, *mTail;
public:
Queue() {
mNum = 0;
mHead = null;
mTail = null;
}
int enQueue() {
struct Index *tmpIndex = (struct Index *)malloc(sizeof(struct Index));
tmpIndex->num = mNum;
tmpIndex->next = null;
mNum++;
if (mTail == null) {
mHead = tmpIndex;
} else {
mTail->next = tmpIndex;
}
mTail = tmpIndex;
}
int outQueue() {
struct Index *tmpIndex;
int nReturn;
if (mHead == null) {
return -1;
}
tmpIndex = mHead;
mHead = mHead->next;
if (mHead == null) {
mTail == null;
}
nReturn = tmpIndex->num;
free(tmpIndex);
return nReturn;
}
}
class BankSimSystem {
private:
QueueManager mQManager;
public:
BankQueueSystem() {
mQManager = new QueueManager();
}
void getOneNum() {
int nRand = random(5);
int nNum;
if nRand <= 2) {
nNum = mQManager.getOneVIPNum();
printf("One people enqueue : N%d" nNum);
} else {
nNum = mQManager.getOneNormalNum();
printf("One people enqueue : V%d" nNum);
}
}
void CallOneNum() {
char *sNum = mQManager.CallOneNum();
if (nNum == -1) {
printf("None in queue");
}
printf("Call the people : %s", sNum);
}
}
class QueueManager {
private:
Queue mNormal;
Queue mVIP;
public:
QueueManager() {
mNormal = new Queue();
mVIP = new Queue();
}
char getOneNormalNum() {
int mNormal.enQueue();
}
int getOneVIPNum() {
return mVip.enQueue();
}
char* CallOneNum() {
char sNum[10];
if (!mVIP.isempty()) {
sprintf(sNum, "V%d",mVIP.outQueue())
return sNum;
}
if (!mNormal.isempty()) {
sprintf(sNum, "N%d",mNormal.outQueue())
return sNum;
}
return null;
}
};
class Queue {
private:
int mNum;
struct Index{
int num;
struct index *next;
} *mHead, *mTail;
public:
Queue() {
mNum = 0;
mHead = null;
mTail = null;
}
int enQueue() {
struct Index *tmpIndex = (struct Index *)malloc(sizeof(struct Index));
tmpIndex->num = mNum;
tmpIndex->next = null;
mNum++;
if (mTail == null) {
mHead = tmpIndex;
} else {
mTail->next = tmpIndex;
}
mTail = tmpIndex;
}
int outQueue() {
struct Index *tmpIndex;
int nReturn;
if (mHead == null) {
return -1;
}
tmpIndex = mHead;
mHead = mHead->next;
if (mHead == null) {
mTail == null;
}
nReturn = tmpIndex->num;
free(tmpIndex);
return nReturn;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个问题太范范了吧……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询