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

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

package task2;/** * 功能:数组、链表实现队列 * Created by liumao on 2019/8/7 */public class Queue implements com.imooc.oop.queue.Queue {    /**     * 数组队列实现     */    public static class ArrayQueue {        private Object[] arrQueue;        private int front;        private int rear;        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 static class LinkedQueue implements com.imooc.oop.queue.Queue {        private Node rear;        private Node front;        private int size;        public LinkedQueue(int size) {            this.size = size;            this.rear = null;            this.front = null;        }        public class Node {            Object t;            Node next;        }        public boolean isEmpty() {            return rear == null;        }        public void enQueue(Object data) {            Node oldLast = front;            front = new Node();            front.next = null;            if (size == 0) {                rear = front;            } else {                oldLast = rear;                rear = front.next;                front.next = rear;            }            size++;        }        public Object deQueue() {            Object t = rear.t;            rear = front.next;            if (size == 0) {                front = null;            }            size--;            return t;        }    }}

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

你可能感兴趣的文章
oracle零碎要点---oracle em的web访问地址忘了
查看>>
Oracle零碎要点---多表联合查询,收集数据库基本资料
查看>>
Oracle静默安装
查看>>
Oracle面试题:Oracle中truncate和delete的区别
查看>>
ThreadLocal线程内部存储类
查看>>
thinkphp 常用SQL执行语句总结
查看>>
Oracle:ORA-00911: 无效字符
查看>>
Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
查看>>
TCP基本入门-简单认识一下什么是TCP
查看>>
tableviewcell 中使用autolayout自适应高度
查看>>
Orcale表被锁
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>
org.tinygroup.serviceprocessor-服务处理器
查看>>