队列的删除(出对)
求大神教我,怎么编程队列的删除!!
程序代码:
namespace { public class Queue<T> { protected SingleLinkedList<T> m_List; public bool IsEmpty { get { return m_List.IsEmpty; } } public int Count { get { return m_List.Count; } } public Queue() { m_List = new SingleLinkedList<T>(); } public Queue(T t) { m_List = new SingleLinkedList<T>(t); } public T DeQueue() { T t = m_List.GetTail(); m_List.RemoveTail(); return t; } public void EnQueue(T t) { m_List.AddHead(t); } public T GetFront() { return m_List.GetTail(); } public T GetRear() { return m_List.GetHead(); } } } Queue<int> q1 = new Queue<int>(); Queue<int> q2 = new Queue<int>(); Random rnd = new Random(); for (int i = 0; i < 20; i++) { int value = rnd.Next(); if (value % 2 != 0) { q1.EnQueue(value); } else { q2.EnQueue(value); } } while (!q1.IsEmpty && !q2.IsEmpty) { Console.WriteLine("奇偶数对:{0},{1}", q1.DeQueue(), q2.DeQueue()); }