要求:
1。設(shè)銀行有A、B兩個(gè)業(yè)務(wù)窗口,A窗口的處理速度是B的2倍(A處理完兩個(gè)顧客時(shí),B處理完一個(gè)顧客)
2.奇數(shù)編號(hào)的顧客到A窗口辦理業(yè)務(wù),偶數(shù)編號(hào)的顧客到B窗口辦理業(yè)務(wù)
當(dāng)不同窗口同時(shí)處理完兩個(gè)顧客時(shí),A窗口顧客優(yōu)先輸出
代碼:文章來源:http://www.zghlxwxcb.cn/news/detail-716206.html
//銀行業(yè)務(wù)隊(duì)列簡單模擬
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define MaxQSize 1000
/*-----循環(huán)隊(duì)列-----*/
typedef int ElementType;
typedef int Position;
typedef struct QNode *PtrToQNode;
struct QNode{
ElementType *Data;
Position Front,Rear;
int MaxSize;
};
typedef PtrToQNode Queue;
Queue CreateQueue(int MaxSize);
bool IsEmpty(Queue Q);
void AddQ(Queue Q,ElementType X);
ElementType DeleteQ(Queue Q);
/*-----隊(duì)列定義結(jié)束-----*/
int main()
{
int N,Customer,i;
Queue A,B;
//初始化隊(duì)列
A=CreateQueue(MaxQSize);
B=CreateQueue(MaxQSize);
printf("請(qǐng)輸入顧客總數(shù):");
scanf("%d",&N);
printf("請(qǐng)輸入%d個(gè)顧客的編號(hào):",N);
for(i=0;i<N;i++){
scanf("%d",&Customer);
if(Customer%2)AddQ(A,Customer);//奇數(shù)
else AddQ(B,Customer);//偶數(shù)
}
printf("客戶處理隊(duì)列:");
//輸出第一個(gè)客戶
if(!IsEmpty(A))
printf("%d ",DeleteQ(A));
else printf("%d ",DeleteQ(B));
while(!IsEmpty(A) && !IsEmpty(B)){
printf("%d ",DeleteQ(A));
printf("%d ",DeleteQ(B));
if(!IsEmpty(A))printf("%d ",DeleteQ(A));
}
while(!IsEmpty(A))//A不為空,B空
printf("%d ",DeleteQ(A));
while(!IsEmpty(B))//B不為空,A空
printf("%d ",DeleteQ(B));
printf("\n");
return 0;
}
Queue CreateQueue(int MaxSize){
Queue Q=(Queue)malloc(sizeof(struct QNode));
Q->Data =(ElementType *)malloc(sizeof(ElementType)*MaxSize);
Q->Front =Q->Rear =0;
Q->MaxSize =MaxSize;
return Q;
}
bool IsEmpty(Queue Q){
return (Q->Front ==Q->Rear) ;
}
void AddQ(Queue Q,ElementType X){
//簡版入隊(duì),不檢查隊(duì)列滿的問題
Q->Rear=(Q->Rear +1)%Q->MaxSize ;
Q->Data [Q->Rear ]=X;
}
ElementType DeleteQ(Queue Q){
Q->Front =(Q->Front +1)%Q->MaxSize ;
return Q->Data[Q->Front ];
}
運(yùn)行:文章來源地址http://www.zghlxwxcb.cn/news/detail-716206.html

到了這里,關(guān)于銀行業(yè)務(wù)隊(duì)列簡單模擬的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!