6)某汽车轮渡口,过江渡船每次能载10辆车过江,过江车辆分为客车类和货车类,上渡船有如下规定:同类车先上船,客车先于货车上船,且每上4辆客车才允许上一辆货车,若等待的客车不足4辆,则以或车代替,若无货车等待,允许客车都上船。使设计算法模拟以上渡口管理。
#include<iostream>
using namespace std;
typedef struct Queue {
Queue* next;
}*L_Queue;
void menu() {
cout << "1:客车入队" << endl;
cout << "2:货车入队" << endl;
cout << "3:渡船入队" << endl;
cout << "0:退出程序" << endl;
cout << "4:显示客车数量" << endl;
cout << "5:显示货车数量" << endl;
}
int empty_queue(L_Queue front)
{
return front == NULL;
}
void inital_queue(L_Queue& front, L_Queue& rear)
{
front = rear=NULL;
}
void add_queue1(L_Queue& front, L_Queue& rear)
{
L_Queue p;
p = new Queue;
p->next = NULL;
if (front == NULL)
front = p;
else
rear->next = p;
rear = p;
}
void put_queue1(L_Queue& front) {
L_Queue p = front;
front = front->next;
delete p;