what is the best way to implement isFull
method for Circular Array Queue?
Tried to do it like this, but don't think it works.
@Override
public boolean isFull() {
return ((rear-front) == -1 || (rear-front) == (size - 1)) ? true : false;
}
A circular queue can be defined as full if the next element to the last element is the first element. Assuming front and rear are the indices of the first and last element you could do something like this.
@Override
public boolean isFull() {
return (rear + 1) % size == front
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.