队列:

队列是一个有序列表,遵循先入先出原则,可以用数组或链表实现

使用场景

用于排队,按顺序执行

public static void Main(string[] args)
{
ArrayQueue<int> queue = new ArrayQueue<int>(1000);
queue.Push(1);
queue.Push(2);
queue.Push(3);
queue.Push(4);
queue.Push(5); Console.WriteLine(queue.Pop());
Console.WriteLine(queue.Pop());
queue.Push(6);
queue.Push(7);
queue.Print();
Console.ReadKey();
}

  数组队列

public class ArrayQueue<T>
{
private int _front = -1; //队首
private int _rear = -1; //队尾
private int _maxSize = 0;
private T[] _arr = null; public ArrayQueue(int maxSize)
{
_maxSize = maxSize;
_arr = new T[maxSize];
} public bool IsFull()
{
return _rear >= _maxSize - 1;
} public bool IsEmpty()
{
return _front >= _rear;
} public void Push(T n)
{
if (this.IsFull())
{
throw new Exception("队列已满");
}
_arr[++_rear] = n;
} public T Pop()
{
if (this.IsEmpty())
{
throw new Exception("队列已空");
}
return _arr[++_front];
} public void Print()
{
if (this.IsEmpty())
{
Console.WriteLine("队列已空");
return;
}
for (int i = _front + 1; i <= _rear; i++)
{
Console.WriteLine(i);
}
}
}

  

最新文章

  1. 怎样学习Java
  2. C语言fgetpos()函数:获得当前文件的读写指针(转)
  3. onselectstart和onselect的使用
  4. Sql Server之旅——第十二站 sqltext的参数化处理
  5. SQL SERVER 2014 安装图解(含 SQL SERVER 2014 安装程序共享)
  6. 修剪花卉(codevs 1794)
  7. Apache的prefork模式和worker模式
  8. Android漫游记(1)---内存映射镜像(memory maps)
  9. [置顶] viewPager控制滑动速度和时间
  10. BZOJ 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课( BFS )
  11. Ubuntu安装微信开发者工具
  12. J2EE架构师之路
  13. NLTK基础
  14. (93)Wangdao.com_第二十六天_鼠标事件
  15. yum upgrade卡在 清理initial-setup-0.3.9.30-1.el7.centos.x86_64
  16. OSI网络体系结构
  17. springboot配置redis
  18. s21day04 python笔记
  19. SVN服务器安装与本地连接
  20. 大型开放式网络课程MOOC的一点体会

热门文章

  1. 专业视频图片水印清除工具丨HitPaw Watermark Remover 2.1.3
  2. 如何为 Debian 11 安装图形用户界面 (GUI)
  3. 基于Axi4_lite的UART串口Verilog代码实现
  4. uniapp 配置钉钉小程序package.json文件
  5. IEC104
  6. redis geo 做距离计算排序分页
  7. 实战记录在 Linux Ubuntu 20.04 安装VNC 远程桌面
  8. go语言web框架-如何使用gin教程+react实现web项目
  9. Java项目引入第三方Jar包
  10. Counting Triangles