資源簡介
某汽車輪渡口,過江渡船每次能載 10 輛車過江。過江車輛分別為客車類和 貨車類,上船有如下規定:同類車先到先上船,客車先于貨車上渡船,且每上 4 輛客 車,才允許上一輛貨車;若等待客車不足 4 輛則以貨車代替;若無貨車等待則允許客 車都上船。設計一個算法模擬渡口管理。(*代表客車,#代表貨車)
代碼片段和文件信息
#include
#include
#define?MAXSIZE?10
#define?MAX?1024
??typedef?char???elemtype;
typedef?struct?SequenQueue
{
elemtype?data[MAXSIZE];
int?firstrear;
}SequenQueue;
SequenQueue?*Init_SequenQueue()
{
SequenQueue?*S;
S=(SequenQueue?*)malloc(sizeof(SequenQueue));
if(S!=NULL)
{
S->first=0;
????S->rear=0;
}
return?S;
}
typedef?struct?Ferry
{
elemtype?data[MAXSIZE];
int?firstreartotalNumbusNumtruckNum;
}Ferry;
Ferry?*Init_Ferry()
{
Ferry?*Q;
Q=(Ferry?*)malloc(sizeof(Ferry));
if(Q!=NULL)
{
Q->first=0;
????Q->rear=0;
Q->truckNum=0;
Q->busNum=0;
Q->totalNum?=0;
}
return?Q;
}
int?Entercar(SequenQueue*?Selemtype?x)
{
if(S->rear>=MAX)
{
return?0;
}
????else
{
S->data[S->rear]=x;
S->rear=S->rear+1;
- 上一篇:傾斜攝影數據
- 下一篇:通信原理期末考試試題及答案.doc
評論
共有 條評論