博客
关于我
数组、链表实现队列
阅读量: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/

你可能感兴趣的文章
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
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-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>
org/hibernate/validator/internal/engine
查看>>
SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
查看>>
ORM sqlachemy学习
查看>>
Ormlite数据库
查看>>
orm总结
查看>>
os.environ 没有设置环境变量
查看>>
os.path.join、dirname、splitext、split、makedirs、getcwd、listdir、sep等的用法
查看>>
os.system 在 Python 中不起作用
查看>>