Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Circular buffer / queue visualization

Featured Replies

Cookie pls doge.png

 

168ab2ab8a9b66755aa657a154a9ba8f.gif

package org.bjornkrols.botre.datastructures.queue;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * Created by Bjorn on 25/05/2015.
 * Last edit: 25/05/2015.
 */
public class CircularArrayQueue<T> implements Queue<T>, Iterable<T> {

    private T[] queue;

    private int front, insert, size;

    public CircularArrayQueue(int capacity){
        queue = (T[]) new Object[capacity];
    }

    /**
     * Inserts the element at the rear of the queue.
     * If the queue is full, the oldest value will be removed and the the second oldest element will become the front element.
     */
    @Override
    public void enqueue(T element) {
        queue[insert] = element;
        insert = (insert + 1) % queue.length;
        if (isFull()) {
            front = (front + 1) % queue.length;
        } else {
            size++;
        }
    }

    @Override
    public T dequeue() {
        if (size == 0) {
            throw new NoSuchElementException("Queue is empty.");
        }
        T element = queue[front];
        queue[front] = null;
        front = (front + 1) % queue.length;
        size--;
        return element;
    }

    @Override
    public boolean isEmpty() {
        return size == 0;
    }

    public boolean isFull() {
        return size == queue.length;
    }

    @Override
    public int size() {
        return size;
    }

    @Override
    public Iterator<T> iterator() {
        return new QueueIterator();
    }

    public class QueueIterator implements Iterator<T> {

        private int current = front;
        private int i;

        @Override
        public boolean hasNext() {
            return i < queue.length;
        }

        @Override
        public T next() {
            T value = queue[current];
            current = (current + 1) % queue.length;
            i++;
            return value;
        }

    }

}

Edited by Botre

such wow :doge:

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.