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

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



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

版权声明


相关文章:

  • 七日杀打开一堆代码(七日杀a16代码)2025-02-14 21:27:07
  • 文字图标生成(文字图标生成器app)2025-02-14 21:27:07
  • ddp贸易术语解释 拖车和报关(ddp和ddu贸易术语解释)2025-02-14 21:27:07
  • st7735s与st7735区别(st7388与st7850)2025-02-14 21:27:07
  • 蓝牙通信地址(蓝牙通信地址怎么查看)2025-02-14 21:27:07
  • 批量删除文件的命令(批量删除文件夹bat)2025-02-14 21:27:07
  • 谷歌身份验证码怎么获取(谷歌验证身份怎么弄)2025-02-14 21:27:07
  • linux删除整个目录命令(linux中删除目录和全部内容)2025-02-14 21:27:07
  • ip域名解析搜索(ip域名解析网)2025-02-14 21:27:07
  • tip期刊审稿速度(tifs期刊投稿难度)2025-02-14 21:27:07
  • 全屏图片