///<summary> /// 出队 ///</summary> ///<returns></returns> ///<exception cref="InvalidOperationException"></exception> public T Dequeue() { if (IsEmpty) { thrownew InvalidOperationException("队列为空."); } //队头元素 T result = items[head]; items[head] = default(T);
//更新队头索引 head++;
//更新元素数量 count--;
//返回结果 return result; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14
privatevoidbutton2_Click(object sender, EventArgs e) { MyQueue<string> quee = new MyQueue<string>();
///<summary> /// 出队 ///</summary> ///<returns></returns> ///<exception cref="InvalidOperationException"></exception> public T Dequeue() { if (IsEmpty) { thrownew InvalidOperationException("队列为空."); } //队头元素 T result = items[head]; items[head] = default(T);
//更新队头索引 head++;
//更新元素数量 count--;
//返回结果 return result; }
///<summary> /// 获取队头 ///</summary> ///<returns></returns> ///<exception cref="InvalidOperationException"></exception> public T Peek() { if (IsEmpty) { thrownew InvalidOperationException("队列为空."); }
///<summary> /// 出队 ///</summary> ///<returns></returns> ///<exception cref="InvalidOperationException"></exception> public T Dequeue() { if (IsEmpty) { thrownew InvalidOperationException("队列为空."); } //队头元素 T result = items[head]; items[head] = default(T);
///<summary> /// 出队 ///</summary> ///<returns></returns> ///<exception cref="InvalidOperationException"></exception> public T Dequeue() { if (IsEmpty) { thrownew InvalidOperationException("队列为空."); } //队头元素 T result = items[head]; items[head] = default(T);
//更新队头索引 head = (head + 1) % items.Length;
//更新元素数量 count--;
//返回结果 return result; }
///<summary> /// 获取队头 ///</summary> ///<returns></returns> ///<exception cref="InvalidOperationException"></exception> public T Peek() { if (IsEmpty) { thrownew InvalidOperationException("队列为空."); }