自定义队列Queue
来源:互联网 发布:网络双向是什么意思 编辑:程序博客网 时间:2024/06/05 19:05
using System;public class MyQueue<T>{ T[] arr; int count = 0; int copacity = 0; public MyQueue() { arr = new T[count]; } public MyQueue(int a) { if (a > count) { arr = new T[a]; copacity = a; } else { arr = new T[count]; copacity = count; } } public int Count { get { return this.count; } } //添加数据 public void Enqueue(T name) { T[] arrT = arr; if (count == copacity) { arr = new T[count + 1]; for (int i = 0; i < count; i++) { arr[i] = arrT[i]; } arr[count] = name; } else if (count < copacity) { arr[count] = name; } else { arr = new T[count + 1]; for (int i = 0; i < count; i++) { arr[i] = arrT[i]; } arr[count] = name; } count++; } //出队 public T Dequeue() { try { T name = arr[0]; T[] arrT = new T[count - 1]; for (int i = 0; i < count - 1; i++) { arrT[i] = arr[i + 1]; } count--; for (int i = 0; i < count; i++) { arr[i] = arrT[i]; } return name; } catch { throw new Exception("没有数据,不能取钱"); } } //移除所有数据 public void Clear() { int j = count; for (int i = 0; i < j; i++) { Dequeue(); } } //返回队头数据 public T Peek() { try { return arr[0]; } catch { throw new Exception("小子你钱包空了,不用再看了"); } } //确定某元素是否在stack中 public bool Contains(T name) { for (int i = 0; i < count; i++) { if (arr[i].Equals(name)) { return true; } } return false; }}
阅读全文
0 0
- 自定义队列Queue
- Queue与Deque队列和自定义堆栈
- queue队列-printer queue
- 队列(queue)
- Queue---队列
- 队列(Queue)
- Queue队列
- Queue队列
- Queue (队列)
- (队列)queue
- 队列Queue
- 队列(queue)
- queue队列
- 队列(Queue)
- 队列<queue>
- 队列queue
- queue 队列
- 队列Queue
- 字符串右移K位
- hdu 2899 导数求最值 浮点数二分
- 445. Add Two Numbers II。
- C语言介绍,C语言解答。
- Flex 布局教程:语法篇
- 自定义队列Queue
- HDU 3652 浅谈数位动态规划朝花夕拾Ver2.0
- Python中Unicode字符串
- PX4代码学习系列博客(6)——offboard模式位置控制代码分析
- tensorflow variable_scope,tf.name_scope, tf.variable, tf.get_varible
- #leetcode编程日记#343. Integer Break
- java 图片文件生成MD5值
- 在centos中视频转音频的命令
- epoll的ET和LT模式下,accept,recv,send写法