LinkedList vs ArrayList

It seems that LinkedList and ArrayList are not interchangeable.
So I am trying to code a custom Queue Class with ArrayList itself.
I managed to code it with Integer, but I would like to use PVector to get rid of all imports.
However, I have problems to add a PVector to the ArrayList.
It gives the error:

The method add() in the type sketch_200420a.PVectorQueue is not applicable for the arguments (int, int, int)

What should be changed?

void setup() {
  PVectorQueue pvq = new PVectorQueue();
  for (int i = 0; i <= 10; i++) {
    pvq.add(i,i,i);
  }  
}  

public class PVectorQueue {
  int front;    // front points to front element in the queue (if any)
  int x, y, z;
  ArrayList<PVector> myArray = new ArrayList<PVector>();

  PVectorQueue() {
    front = 0;
  }

  public PVector add() {
    myArray.add(new PVector(x,y,z));
  }

  public PVector remove() {
    PVector res = myArray.get(front);
    myArray.remove(0);    
    return res;
  } 

  public PVector peek() {
    if (isEmpty()) {
      println("UnderFlow\nProgram Terminated");
      exit();
    } 
    return (PVector) myArray.get(0);
  }

  public int size() {
    return myArray.size();
  }

  public Boolean isEmpty() {
    return (size() == 0);
  }
}
1 Like