数据结构---队列(C#)
2010-04-09 14:04
190 查看
namespace DateStructrue { public interface IQueue<T> : IDateStructrue { void EnQueue(T item); T DeQueue(); T GetFront(); //T this[int index] { get; set; } bool IsFull { get; } } }
namespace DateStructrue { public class Queue<T>:IQueue<T> { private T[] _item; private int _head; private int _tail; public Queue() : this(10) { } public Queue(int size) { _item = new T[size]; } #region IQueue<T> Members public void EnQueue(T item) { if (IsFull) { T[] destinationArray = new T[this._item.Length + 10]; if (this._head < this._tail) { Array.Copy(this._item, this._head, destinationArray, 0, this.Count); } else { Array.Copy(this._item, 0, destinationArray, 0, this._item.Length); } this._item = destinationArray; } this._item[_tail++] = item; } public T DeQueue() { T temp = default(T); if (IsEmpty){ return temp; } return temp = this._item[_head++]; } public T GetFront() { T temp = default(T); if (IsEmpty) { return temp; } return temp = this._item[_head]; } public bool IsFull { get { return this._tail % this._item.Length == 0; } } #endregion #region IDateStructrue Members public int Count { get { return this._tail - this._head; } } public void Clear() { this._head = this._tail = 0; } public bool IsEmpty { get { return this._head == this._tail; } } #endregion } }
相关文章推荐
- 数据结构(C#):队列
- [导入]队列(C#数据结构学习三)
- 数据结构 C#描述 第五章 栈和队列
- C# 队列数据结构 (三)
- 队列(C#数据结构学习三)
- C# 数据结构 之 堆栈和队列
- C#数据结构回顾之循环队列
- C语言数据结构中链队列细节
- c# 写着玩的,两个Task并发,一个写队列一个读队列的异常情况
- Python笔记——几种数据结构的实现:栈、队列及二叉树
- 数制转换器(c语言编写,应用数据结构的栈和队列)
- JAVA数据结构---循环队列
- 数据结构--队列
- 数据结构(C#版)概念整理
- 数据结构(三)之队列ADT
- 黑马程序员使用LinkedList模拟一个堆栈或者队列数据结构。
- 数据结构3.1——队列
- 数据结构第七周项目3--负数把正数赶出队列
- C# 队列
- java 实现数据结构之队列