type
status
date
slug
summary
tags
category
icon
password

数组实现队列 详细讲解

队列的介绍

notion image
notion image

队列的一个使用场景

银行排队的案例
notion image

数组模拟队列的思路:

notion image
1、定义一个数组 arr[maxSize] 作为该队列 2、rear定义为队尾指针 3、front定义为对头指针 4、入队addQueue,将队尾指针往后移,rear+1的情况下,要判断队列的元素是否已满,已满的条件为rear=maxSize-1; 5、出队outQueue,将队头的元素往后移,front+1的情况下,要判断队列的元素是否为空,为空的条件为rear=front;

代码实现

问题以及需要优化的点
1、目前的数组只能使用一次,不能达到复用的效果 2、将该数组使用算法,改成环形数组,取模%
环形数组详见,我的下一篇博客
https://blog.csdn.net/cativen/article/details/124366550
 
数组实现环形队列 详细讲解普里姆算法
IT小舟
IT小舟
微信公众号:IT小舟
公告
type
status
date
slug
summary
tags
category
icon
password
notion image
你好,我是小舟。 欢迎来到我的博客,我喜欢运动、阅读、音乐和写作。如果有什么想要交流的,可以加我微信:upcodezhou。再次感谢你的光临!
notion image