车辆渡江问题

6)某汽车轮渡口,过江渡船每次能载10辆车过江,过江车辆分为客车类和货车类,上渡船有如下规定:同类车先上船,客车先于货车上船,且每上4辆客车才允许上一辆货车,若等待的客车不足4辆,则以或车代替,若无货车等待,允许客车都上船。使设计算法模拟以上渡口管理。

#include<iostream>
using namespace std;
typedef struct Queue {
   
	//int date;
	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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值