当前位置:网站首页 > 编程语言 > 正文

环形队列一定优于非环形队列吗(环形队列是一种什么结构)



public class cireQueue {

private int maxsize;
private int rear;
private int front;
private int []arr;

public cireQueue(int size)
{
maxsize=size;
arr=new int[maxsize-1];
}
//判断是否为空
public boolean isempty()
{
return rear==front;
}
//判断是否满了
public boolean isfull()
{

return (rear+1)%maxsize==front;
}
//添加元素进入队列
public void addqueque(int a)
{
if (isfull())
{
throw new RuntimeException("队列已经满");
}
arr[rear]=a;
rear=(rear+1)%maxsize;
}
//取出队列的元素

public int putqueque()
{
if (isempty())
{
throw new RuntimeException("队列为空");
}
int value=arr[front];
front=(front+1)%maxsize;
return value;
}
//个数
public int size()
{
return (rear+maxsize-front)%maxsize;
}
//显示全部元素
public void showqueue()
{
if (isempty())
{
throw new RuntimeException("队列为空");
}
for (int i = front; i <front+size(); i++) {
System.out.printf("arr[%d]=%d ",i%maxsize,arr[i%maxsize]);

}
}

//显示头元素
public int head()
{
if (isempty())
{
throw new RuntimeException("队列为空");
}

return arr[front];
}
}
到此这篇环形队列一定优于非环形队列吗(环形队列是一种什么结构)的文章就 介绍到这了,更多相关 内容请继续浏览下面的相关 推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • 文字图标生成(文字图标生成器app)2025-02-14 21:27:07
  • 流量回放工具(流量回放是什么意思)2025-02-14 21:27:07
  • de4dot源码分析(dehazenet源码下载)2025-02-14 21:27:07
  • yml文件不是绿色的(yml文件颜色不对)2025-02-14 21:27:07
  • Tp9950(tp9950芯片支持360全景吗)2025-02-14 21:27:07
  • 批量删除文件的命令(批量删除文件夹bat)2025-02-14 21:27:07
  • libpng.dll丢失(libhl.dll丢失)2025-02-14 21:27:07
  • 颜色代码查询对照表(颜色代码对应表)2025-02-14 21:27:07
  • 聊天网页制作(聊天网页制作方法)2025-02-14 21:27:07
  • 指数与对数视频讲解(指数和对数教学视频)2025-02-14 21:27:07
  • 全屏图片