• 数组实现队列


    /**
     * @author:liuxincheng
     * @description:
     * @date:created in 2019/1/22 13:49
     * @modified by liuxincheng
     */
    
    public class ArrayQueue<T> {
        /**
         * 队列数组
         */
        private T[] queue;
        /**
         * 头下标
         */
        private int head;
        /**
         * 尾下标
         */
        private int tail;
        /**
         * 元素个数
         */
        private int count;
    
        public ArrayQueue() {
            queue = (T[]) new Object[10];
            // 头下标为零
            this.head = 0;
            this.tail = 0;
            this.count = 0;
        }
    
        public ArrayQueue(int size) {
            queue = (T[]) new Object[size];
            this.head = 0;
            this.tail = 0;
            this.count = 0;
        }
    
        /**
         * 入队
         *
         * @param t
         * @author: liuxincheng
         * @date: 2019/1/22 13:53
         * @return: boolean
         */
        public boolean inQueue(T t) {
            if (count == queue.length) {
                return false;
            }
            // 如果不为空就放入下一个
            queue[tail++ % (queue.length)] = t;
            count++;
            return true;
        }
    
        /**
         * 出队
         *
         * @param
         * @author: liuxincheng
         * @date: 2019/1/22 13:54
         * @return: T
         */
        public T outQueue() {
            // 如果是空的那就不能再出栈了
            if (count == 0) {
                return null;
            }
            count--;
            return queue[head++ % (queue.length)];
        }
    
        /**
         * 查队列
         *
         * @param
         * @author: liuxincheng
         * @date: 2019/1/22 13:55
         * @return: T
         */
        public T showHead() {
            if (count == 0) {
                return null;
            }
            return queue[head];
        }
    
        /**
         * 判满
         *
         * @param
         * @author: liuxincheng
         * @date: 2019/1/22 13:56
         * @return: boolean
         */
        public boolean isFull() {
            return count == queue.length;
        }
    
        /**
         * 判空
         *
         * @param
         * @author: liuxincheng
         * @date: 2019/1/22 13:56
         * @return: boolean
         */
        public boolean isEmpty() {
            return count == 0;
        }
    }
  • 相关阅读:
    RAID10磁盘阵列损坏的修复
    Linux系统中物理劵增加、删除;卷组的扩容、缩容;逻辑卷的增加与删除
    Ubuntu alternate和desktop区别 zz
    freecommander 快捷键列表 zz
    调试小技巧
    Java框架
    获取url的文件名(动态改变css)
    Urlrewrite方法集
    NVelocity模板引擎,初级体验,非常有用的东东.(转)
    CodeSmith&NetTiers Step by Step[转]
  • 原文地址:https://www.cnblogs.com/lxcmyf/p/10303483.html
Copyright © 2020-2023  润新知