博客
关于我
数组、链表实现队列
阅读量:199 次
发布时间:2019-02-28

本文共 1724 字,大约阅读时间需要 5 分钟。

package task2;/** * 功能:数组、链表实现队列 * Created by liumao 2019/8/7 0007 **/public class Queue
{ public class ArrayQueue { private Object[] arrQueue; private int front; private int rear; public ArrayQueue() { } public ArrayQueue(int size) { arrQueue = new Object[size]; front = 0; rear = 0; } public boolean enQueue(Object obj) { if ((rear+1)%arrQueue.length==front){ return false; } arrQueue[rear] = obj; rear = (rear+1)%arrQueue.length; return true; } public Object deQueue() { if (rear==front){ return null; } Object obj = arrQueue[front]; front = (front+1)%arrQueue.length; return obj; } } public class LinkedQueue { Node rear; Node front; private int size; public LinkedQueue(int size) { this.size = size; this.rear = null; this.front = null; } public class Node{ T t; Node next; } public boolean isEmpty(){ return rear == null; } public void enQueue(T data) { Node oldLast = front; front = new Node(); front.next = null; if (size==0){ front=rear; }else { oldLast = front; } size ++; } public T deQueue() { T t = rear.t; rear = front.next; if (size==0) front=null; size--; return t; } }}

转载地址:http://afps.baihongyu.com/

你可能感兴趣的文章
nginx开机启动脚本
查看>>
nginx异常:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf
查看>>
nginx总结及使用Docker创建nginx教程
查看>>
nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:128
查看>>
nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in usrlocalnginxconfnginx.conf128
查看>>
nginx日志分割并定期删除
查看>>
Nginx日志分析系统---ElasticStack(ELK)工作笔记001
查看>>
Nginx映射本地json文件,配置解决浏览器跨域问题,提供前端get请求模拟数据
查看>>
nginx最最最详细教程来了
查看>>
Nginx服务器---正向代理
查看>>
Nginx服务器上安装SSL证书
查看>>
Nginx服务器基本配置
查看>>
Nginx服务器的安装
查看>>
Nginx标准配置文件(包括反向代理、大文件上传、Https证书配置、文件预览等)
查看>>
Nginx模块 ngx_http_limit_conn_module 限制连接数
查看>>
Nginx模块 ngx_http_limit_req_module 限制请求速率
查看>>
nginx添加模块与https支持
查看>>
nginx状态监控
查看>>
Nginx用户认证
查看>>
Nginx的location匹配规则的关键问题详解
查看>>