⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arrayqueue.java

📁 Java code Bankline to allocated the source for next
💻 JAVA
字号:
/** * Title:        ArrayQueue.java * Description:  A Queue class implemented using array */public class ArrayQueue {	private int maxSize;	private Object [] entry;	private int front;	private int rear;	private int count;	int Teller =0;	int customer=0;    public ArrayQueue(int size) {		maxSize = size;    	entry = new Object[maxSize];    	count = 0; front = 0; rear = -1;    }	public ArrayQueue() {		this(10);	}	public boolean empty() {		return count <= 0;	}	public boolean full() {		return count == maxSize;	}	public int count_customer () {		int i = 0;		while (count!= 0) {			i++;			return i ;		}		return i;	}public  int addTellers (int c_customer, int maxTellers) {this.Teller=Teller;int customer = c_customer;if (Teller <= maxTellers)	if (customer > 0) && (customer <= 20)	Teller += 0;	else if (customer > 20) && (customer <= 30)	Teller += 1;	else if (customer > 30) && (customer <= 40)	Teller += 1;	else if (customer > 40) && (customer <= 50)	Teller += 1;	else if (customer > 50) && (customer <= 60)	Teller += 1;	else if (customer > 60) && (customer <= 70)	Teller += 1;	else if (customer > 70) && (customer <= 80)	Teller += 1;    else if (customer > 80) && (customer <= 90)	Teller += 1;	else if (customer > 90) && (customer <= 100)	Teller += 1;	else if (customer > 100)	Teller += 1;	else{	System.out.println("Teller number has over the limit!");	break;}	return Teller;}public  int removeTellers (int c_customer, int maxTellers) {this.Teller=Teller;int customer = c_customer;if (Teller <= minTellers)	if (customer > 100)	Teller -= 0;	else if (customer > 90) && (customer <= 100)	Teller -= 1;	else if (customer > 80) && (customer <= 90)	Teller-= 1;	else if (customer > 70) && (customer <= 80)	Teller -= 1;	else if (customer > 60) && (customer <= 70)	Teller -= 1;	else if (customer > 50) && (customer <= 60)	Teller -= 1;	else if (customer > 40) && (customer <= 50)	Teller -= 1;    else if (customer > 30) && (customer <= 40)	Teller -= 1;	else if (customer > 20) && (customer <= 30)	Teller -= 1;	else if (customer > 1) && (customer <= 20)	Teller -= 1;	else{	System.out.println("Teller number has lower than the limit!");	break;}	return Teller;}// public int addTellers (int customer, int Teller) {//	if (customer > 0) && (customer <= 20)//	Teller = 1;//	if (customer > 20) && (customer <= 30)//	Teller = 2;//	if (customer > 30) && (customer <= 40)//	Teller = 3;//	if (customer > 40) && (customer <= 50)//	Teller = 4;//	if (customer > 50) && (customer <= 60)//	Teller = 5;//	if (customer > 60) && (customer <= 70)//	Teller = 6;//	if (customer > 70) && (customer <= 80)//	Teller = 7;//   if (customer > 80) && (customer <= 90)//	Teller = 8;//	if (customer > 90) && (customer <= 100)//	Teller = 9;//	if (customer > 100)//	Teller = 10;////	return Teller;//}	public void enqueue( Object item ) throws QueueFullException {		if (count < maxSize) {			count++;			if (rear < maxSize-1)				rear++;			else				rear = 0;			entry[rear] = item;		} else			throw new QueueFullException();	}	public Object dequeue() throws EmptyQueueException {		if (count <= 0)			throw new EmptyQueueException();		count--;		Object temp = entry[front];		if (front < maxSize-1)			front++;		else			front = 0;		return temp;	}	public String toString() {		String s = "front [ ";		int index = front;		for (int i = 0; i < count; i++) {			s = s + entry[index] + " ";			if (index < maxSize-1)				index++;			else				index = 0;		}		s = s + "] rear";		return s;	}} // class ArrayQueueclass EmptyQueueException extends RuntimeException {	public EmptyQueueException () {		super("Queue is empty");	}} // class EmptyQueueExceptionclass QueueFullException extends RuntimeException {	public QueueFullException () {		super("Queue is full");	}} // class QueueFullException

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -