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

你可能感兴趣的文章
OAuth2:项目演示-模拟微信授权登录京东
查看>>
OA系统多少钱?OA办公系统中的价格选型
查看>>
OA系统选型:选择好的工作流引擎
查看>>
OA让企业业务流程管理科学有“据”
查看>>
OA项目之我的会议(会议排座&送审)
查看>>
OA项目之我的会议(查询)
查看>>
Object c将一个double值转换为时间格式
查看>>
object detection之Win10配置
查看>>
object detection训练自己数据
查看>>
object detection错误Message type "object_detection.protos.SsdFeatureExtractor" has no field named "bat
查看>>
object detection错误之Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
查看>>
object detection错误之no module named nets
查看>>
Object of type 'ndarray' is not JSON serializable
查看>>
Object Oriented Programming in JavaScript
查看>>
object references an unsaved transient instance - save the transient instance before flushing
查看>>
Object.assign用法
查看>>
Object.create
查看>>
Object.keys()的详解和用法
查看>>
objectForKey与valueForKey在NSDictionary中的差异
查看>>
Objective - C 小谈:消息机制的原理与使用
查看>>