Java 数据结构之队列
发布日期:2021-06-30 22:37:40
浏览次数:2
分类:技术文章
本文共 1450 字,大约阅读时间需要 4 分钟。
一、概述:
1、说明:
队列的原则时先进先出,就像生活中排队取票一样,谁排在前面谁先得到2、有五个属性:
1)数组元素 2)最大空间 3)长度 4)队头 5)队尾3、示例图:
二、代码实现
/** * @描述 对列 * @项目名称 Java_DataStruct * @包名 com.java.stack * @类名 Queue * @author chenlin * @date 2011年6月5日 下午8:12:47 * @version 1.0 * @SVN $Rev$ */public class Queue { private long[] arr; private int maxSize;// 最大空间 private int len;// 有效长度 private int head;// 队头 private int end;// 队尾 public Queue(int size) { this.maxSize = size; this.arr = new long[maxSize]; this.len = 0; this.head = 0; this.end = -1; } /** * 从队尾插入数据 * * @param value */ public void insert(long value) { arr[++end] = value; len++; } /** * 从队头移除数据 */ public long remove() { len--; return arr[head++]; } /** * 判断是否为空 * * @return */ public boolean isEmpty() { return (len == 0); } /** * 判断是否满了 * * @return */ public boolean isFull() { return (len == maxSize - 1); } /** * 获得队列的有效长度 * * @return */ public int size() { return len; } public static void main(String[] args) { Queue queue = new Queue(50); queue.insert(22); queue.insert(33); queue.insert(44); queue.insert(534); queue.insert(21); queue.insert(55); while (!queue.isEmpty()) { System.out.println(queue.remove()); } }}
转载地址:https://lovoo.blog.csdn.net/article/details/51591406 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
网站不错 人气很旺了 加油
[***.192.178.218]2024年04月09日 04时57分44秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
WebService的简单案例记录(Java)
2019-04-30
Html利用PHP与MySQL交互
2019-04-30
dos简单命令
2019-04-30
mysql的安装与卸载与Navicat远程连接
2019-04-30
java实现稀疏数组及将稀疏数组存入硬盘中
2019-04-30
2021-05-18
2019-04-30
Flutter 使用插件打开相册、相机
2019-04-30
libuv实现tcp代理服务器
2019-04-30
libuv实现ping包发送和接收
2019-04-30
基础架构系列篇-CENTOS7安装NGINX
2019-04-30
基础架构系列篇-系统centos7安装docker+COMPOSE
2019-04-30
基础架构系列篇-NGINX部署VUE
2019-04-30
基础架构系列篇-系统centos7安装kafka
2019-04-30
基础架构系列篇-系统centos7中docker安装分布式文件存储服务minio
2019-04-30
知识点记录-java判断系统是linux或windows
2019-04-30
知识点记录-springboot静态资源映射路径
2019-04-30
微服务springcloud2系列篇-配置与注册nacos组件
2019-04-30
用户权限设计-基于RBAC模型
2019-04-30
微服务springcloud2系列篇-网关GATEWAY跨域问题
2019-04-30
软件质量的8个特性
2019-04-30