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

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
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天瞳月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值