---
title: "Queue 队"
author: "shenyu"
date: "2008-04-06T13:36:17Z"
tags: ["Flash"]
slug: "queue"
draft: false
lastmod: "2008-04-06T13:36:17Z"
id: 179828
url: "https://shenyu.iteye.com/blog/179828"
---

指定最大值的队，底层用数组实现

> 构造函数：指定最大容量
> 
> put：放入
> 
> get：取出
> 
> isEmput：是否为空

其他实现请参考[LinkedQueue](179710)

```
class Queue {
	private int length;
	private int begin = -1;
	private int end = -1;
	private int[] array;
	Queue(int capacity) {
		array = new int[capacity];	
	}

	void put(int value) {
		assert length < array.length;
		if(end ==  array.length - 1) end = -1;
		array[++end] = value;
		length++;
	}

	int get() {
		assert length > 0;
		length--;
		if(begin ==  array.length - 1) begin = -1;
		return array[++begin];
	}

	boolean isEmpty() {
		return length == 0;
	}

}
```