Я изучаю Круговую очередь.Получение арифметического исключения.Пожалуйста, помогите мне обработать это исключение.
import java.util.ArrayList;class MyCircularQueue {
/** Initialize your data structure here. Set the size of the queue to be k. */
private ArrayList<Integer> list;
private int head = -1;
private int tail = -1;
private int count = 0;
public MyCircularQueue(int k) {
list = new ArrayList<Integer>(k);
}
/** Insert an element into the circular queue. Return true if the operation is successful. */
public boolean enQueue(int value) {
if(list.isEmpty()){
tail = (tail+1) % list.size();
list.add(tail);
count++;
if(head == -1){
tail = head;
}
return true;
}
return false;
}
/** Delete an element from the circular queue. Return true if the operation is successful. */
public boolean deQueue() {
if(!list.isEmpty()){
int ele = list.get(head);
head = (head+1) % list.size();
list.remove(ele);
count--;
return true;
}
return false;
}
/** Get the front item from the queue. */
public int Front() {
int a =list.get(head);
return a;
}
/** Get the last item from the queue. */
public int Rear() {
int b = list.get(tail);
return b;
}
/** Checks whether the circular queue is empty or not. */
public boolean isEmpty() {
if(list.isEmpty()){
return true;
}
return false;
}
/** Checks whether the circular queue is full or not. */
public boolean isFull() {
if(list.size() == count){
return true;
}
return false;
}
}
/ ** * Ваш объект MyCircularQueue будет создан и назван так: * MyCircularQueue obj = new MyCircularQueue (k);* логическое param_1 = obj.enQueue (значение);* логическое param_2 = obj.deQueue ();* int param_3 = obj.Front ();* int param_4 = obj.Rear ();* boolean param_5 = obj.isEmpty ();* логическое param_6 = obj.isFull ();* /