银行排队系统源程序清单
- 格式:doc
- 大小:62.00 KB
- 文档页数:30
三.源程序清单
CSeqBankQueue.cs类代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace 银行排队系统
{
class CSeqBankQueue : CSeqQueue
{
private int callnumber;//记录系统自动产生的新来顾客的服务号
//叫号属性
public int Callnumber
{
get
{
return callnumber;
}
set
callnumber = value;
}
}
public CSeqBankQueue() { }
public CSeqBankQueue(int size) : base(size) { } //获得服务号码
public int GetCallnumber()
{
if ((IsEmpty()) && callnumber == 0)
callnumber = 1;
else
callnumber++;
return callnumber;
}
}
//服务窗口类
class ServiceWindow
{
IBankQueue bankQ;
public IBankQueue BankQ
{
{
return bankQ;
}
set
{
bankQ = value;
}
}
public void Service()
{
while (true)
{
Thread.Sleep(10000);
if (!bankQ.IsEmpty())
{
Console.WriteLine();
lock (bankQ)
{
Console.WriteLine("请{0}号到{1}号窗口!", bankQ.DeQueue(), );
}
}
}
}
}
CSeqQueue.cs类代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 银行排队系统
{
public class CSeqQueue
{
private int maxsize; //循环顺序队列的容量
private T[] data; //数组,用于存储循环顺序队列中的数据元素
private int front; //指示最近一个己经离开队列的元素所占的位置
private int rear; //指示最近一个进行入队列的元素的位置
//索引器
public T this[int index]
{
get
{
return data[index]; }
set
{
data[index] = value; }
}
//容量属性
public int Maxsize
{
get
{
return maxsize;
}
set
{
maxsize = value;
}
//队头指示器属性
public int Front
{
get
{
return front; }
set
{
front = value; }
}
//队尾指示器属性
public int Rear
{
get
{
return rear; }
set
rear = value;
}
}
//初始化队列
public CSeqQueue() { }
public CSeqQueue(int size)
{
data = new T[size];
maxsize = size;
front = rear = -1;
}
//入队操作
public void EnQueue(T elem)
{
if (IsFull())
{
Console.WriteLine("Queue is full"); return;
}
rear = (rear + 1) % maxsize; ;
data[rear] = elem;
}
//出队操作
public T DeQueue()
{
if (IsEmpty())
{
Console.WriteLine("Queue is empty"); return default(T);
}
front = (front + 1) % maxsize;
return data[front];
}
//获取队头数据元素
public T GetFront()
{
if (IsEmpty())
{
Console.WriteLine("Queue is empty!"); return default(T);
}
return data[(front + 1) % maxsize];