• 数组实现队列


    /**
     * @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;
        }
    }
  • 相关阅读:
    03.部署 kubectl 命令行工具
    02.创建 CA 证书和秘钥
    01.组件版本和集群环境
    23.kubernetes 组件版本和配置策略
    22.Kubernetes Ingress: HTTP 7层路由机制
    Python程序中#-*-coding: UTF-8 -*-的作用
    Python程序中首行#!/usr/bin/env python的作用
    mac install php dev
    linux的nohup disown setsid screen
    linux 常用查找命令 小技巧
  • 原文地址:https://www.cnblogs.com/lxcmyf/p/10303483.html
Copyright © 2020-2023  润新知