数据结构:用队列模拟理发店的排队情况(C#)

本文使用C#实现了一个模拟理发店排队等待的程序,顾客到达时间随机,理发时间20到30分钟。程序计算了顾客在店内平均逗留时间和队列平均长度。对于N个椅子和T小时的营业时间,该程序能分析顾客的等待情况和理发馆运营状况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目内容:使用的排队现象,通过仿真手法评估其营业状况。
*基本要求:设某理发馆有N把理发椅,可同时为N位顾客进行理发。
*当顾客进门时,若有空椅,则可以立即坐下理发,否则需要依次排队等候。
*一旦有顾客理完发离去时,排在队头的顾客便可开始理发。
*若理发馆每天连续营业T小时,求一天内顾客在理发馆内的平均逗留时间
*顾客排队等候的队列平均长度

N和T在运行的时候输入

用C#写的,有注释,很混乱,请高人指教~~

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Collections;
  5. namespace 队列应用
  6. {
  7.     class Seat
  8.     {
  9.       
  10.         public  bool IsFree;
  11.         public Customer cus=null;
  12.         public Seat(bool b) 
  13.         {
  14.             IsFree = b;      
  15.         }
  16.     }
  17.     class Customer
  18.     {
  19.         public int cometime;
  20.         public int timetogo;
  21.         public int cost =30- new Random().Next(10);//理发需要20~30分钟
  22.         
  23.         public Customer() { }
  24.     }
  25.     class Program
  26.     {
  27.         static void Main(string[] args)
  28.         {
  29.             System.Console.WriteLine("每天营业多少小时?");
  30.             int workinghours = int.Parse(Console.ReadLine());
  31.             System.Console.WriteLine("有多少个椅子?");
  32.             int seats = int.Parse(Console.ReadLine());
  33.             Process(seats,workinghours);
  34.             Console.ReadLine();
  35.         }
  36.         static void Process (int num,int time)
  37.         {
  38.             //------------准备变量------------------------
  39.             Queue q = new Queue();//队列
  40.             Seat[] S=new Seat[num];//所有的椅子
  41.             for (int i = 0; i <num; i++)//初始化椅子
  42.             {
  43.                 S[i] = new Seat(true);
  44.                 S[i].cus = null;
  45.        
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值