java 数据结构之 顺序存储结构 队列

来源:互联网 发布:linux ant命令行 编辑:程序博客网 时间:2024/04/27 16:10
package com.xdl.data_stru;import org.hamcrest.core.Is;/** * @author xudaolong  * 队列:先进先出,如排队买票,先排先买到; * 核心 : "假溢出",构件环模型,对队列头尾指针进行判断,相当重置; * rear= (rear+1)%max_queue; * front=(front+1)%max_queque; */@SuppressWarnings("unused")public class Day_Four_SeqQueue<E> {    private int max_queue;//需要初始化    private Object[] data;        private int front;    private int rear;    private int len;        private void init(int max_queue) {this.max_queue = max_queue;this.data = new Object[max_queue];this.front = 0;this.rear = 0;this.len =0;    }    private boolean check_queue_full() {if ((this.rear+1)%max_queue == this.front) {    return true;}return false;    }    private boolean push_queue(E e) {if (!check_queue_full()) {    this.rear = (this.rear+1)%max_queue;    this.data[this.rear] =e;    this.len++;    return true;}return false;    }    @SuppressWarnings("unchecked")    private E out_queue() {if (!check_queue_full()) {    this.front = (this.front +1)%max_queue;    this.len--;    return  (E)this.data[this.front];}return null;    }        @SuppressWarnings("unchecked")    private E get_front() {if (!check_queue_full()) {    return (E)this.data[(this.front+1)%max_queue];}return null;    }        private boolean  is_null() {/*也可以this.rear=this.front代替*/if (this.len==0) {    return true;}return false;    }}

0 0
原创粉丝点击