using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Diagnostics;
namespace Data
{
//优先级
public struct Pqitem
{
public int priority;
public string name;
}
//构造的队列
public class CQueue
{
private ArrayList pqueue;
//构造器
public CQueue()
{
pqueue = new ArrayList();
}
//加入队列
public void EnQueue(object item)
{
pqueue.Add(item);
}
//删除队列
public object DeQueue(bool isok)
{
//优先级
if (isok)
{
object[] items;
int min;
items = pqueue.ToArray();
min = ((Pqitem)items[0]).priority;
for (int i = 0; i <= items.GetUpperBound(0); i++)
{
if (((Pqitem)items[i]).priority < min)
{
min = ((Pqitem)items[i]).priority;
}
pqueue.Clear();
int x;
for (x = 0; x <= items.GetUpperBound(0); x++)
{
if (((Pqitem)items[x]).priority == min && ((Pqitem)items[x]).name != "")
{
pqueue.Add(items[x]);
}
}
}
}
object obj = pqueue[0];
pqueue.RemoveAt(0);
return obj;
}
//读取顶
public object Peek()
{
return pqueue[0];
}
//清空队列
public void ClearQueue()
{
pqueue.Clear();
}
//队列的长度
public int Count()
{
return pqueue.Count;
}
}
class Program
{
static void Main(string[] args)
{
//构造的队列实现的,有优先级的
//CQueue erwait = new CQueue();
//Pqitem[] erpatient = new Pqitem[3];
//Pqitem nexpatient;
//erpatient[0].name = "XiaoMing";
//erpatient[0].priority = 1;
//erpatient[1].name = "DaMao";
//erpatient[1].priority = 0;
//erpatient[2].name = "ErMao";
//erpatient[2].priority = 3;
//for (int i = 0; i <= erpatient.GetUpperBound(0); i++)
// erwait.EnQueue(erpatient[i]);
//nexpatient = (Pqitem)erwait.DeQueue(true);
//Console.WriteLine(nexpatient.name);
//构造的队列实现的,无优先级的
//CQueue erwait = new CQueue();
//erwait.EnQueue("输出1");
//erwait.EnQueue(1);
//erwait.EnQueue("输出2");
//Console.WriteLine(erwait.DeQueue(false).ToString());
//Console.WriteLine(erwait.DeQueue(false).ToString());
//Console.WriteLine(erwait.DeQueue(false).ToString());
//自身的队列,Queue类
Queue queue = new Queue();
queue.Enqueue("输出1");
queue.Enqueue(1);
queue.Enqueue("输出2");
Console.WriteLine(queue.Count);
Console.WriteLine(queue.Dequeue());
}
}
}