Java 使用标准类向量的实例来实现队列。此实现与基于阵列的方法相比如何?

Java 使用标准类向量的实例来实现队列。此实现与基于阵列的方法相比如何?,java,for-loop,syntax-error,Java,For Loop,Syntax Error,这是我的密码。我有一个奇怪的错误,我想不出来。我们将非常感谢您的任何帮助。我是这个级别的初学者 public interface QueueInterface<T> { public void enqueue(T newEntry); public T dequeue(); public T getFront(); public boolean isEmpty(); public void clear(); 公共接口队列接口 { 公共无效排队(T new

这是我的密码。我有一个奇怪的错误,我想不出来。我们将非常感谢您的任何帮助。我是这个级别的初学者

public interface QueueInterface<T>
{
  public void enqueue(T newEntry);

  public T dequeue();

  public T getFront();

  public boolean isEmpty();

  public void clear();
公共接口队列接口
{
公共无效排队(T newEntry);
公共T出列();
公共T getFront();
公共布尔值为空();
公共空间清除();
现在我把上面代码实现的Vector类的代码放进去。我需要这方面的帮助。我认为for循环中有一个错误,但我不确定

    import java.util.Vector;
public class VectorQueue implements QueueInterface
{
  private Vector queue;
  private int frontIndex;
  private int backIndex;

  private boolean initialized=false;
  private static final int DEFAULT_CAPACITY= 50;
  private static final int MAX_CAPACITY= 1000;

  public VectorQueue()
  {
    queue=new Vector<>();
    frontIndex=backIndex=0;

  }
  public void enqueue(T newEntry)
  {
    backIndex++;
    queue.add(backIndex, newEntry);

    if(frontIndex==0)
      frontIndex++;
  }
    public T dequeue()
  {
    if(frontIndex!=0)
    {
      T rEntry=queue.elementAt(frontIndex);
      for (int i =frontIndex;i++)
             queue.add(frontIndex, queue.elementAt(frontIndex+1));
           queue.remove(backIndex);
           backIndex--;
           if(backIndex==0)
             frontIndex=0;
           return rEntry;
    }
    return null;
    }
    public T getFront()
    {
      if(frontIndex!=0)
        return queue.elementAt(frontIndex);
      return null;
    }
    public boolean isEmpty()
    {
      if(backIndex==0)
        return true;
      return false;
    }
    public void clear()
    {
      int index=backIndex;
      for(int i=frontIndex;i<=backIndex;i++)
        queue.removeElementAt(index--);
      frontIndex=backIndex=0;
    }
  }
import java.util.Vector;
公共类VectorQueue实现了QueueInterface
{
专用向量队列;
私人指数;
私有整数反向索引;
私有布尔初始化=false;
专用静态最终int默认_容量=50;
专用静态最终int最大容量=1000;
公共向量机()
{
队列=新向量();
frontIndex=backIndex=0;
}
公共无效排队(T新条目)
{
backIndex++;
添加(backIndex,newEntry);
如果(frontIndex==0)
frontIndex++;
}
公共T出列()
{
如果(frontIndex!=0)
{
T rEntry=queue.elementAt(frontIndex);
for(int i=frontIndex;i++)
add(frontIndex,queue.elementAt(frontIndex+1));
queue.remove(反向索引);
反向索引--;
如果(反向索引==0)
frontIndex=0;
归还租金;
}
返回null;
}
公共T getFront()
{
如果(frontIndex!=0)
返回队列.elementAt(frontIndex);
返回null;
}
公共布尔值为空()
{
如果(反向索引==0)
返回true;
返回false;
}
公共空间清除()
{
int-index=反向索引;

对于(int i=frontIndex;iI认为for循环中存在错误,实际上错误不在for循环中,但错误存在于人们为循环编写的众多方式中为什么要手动处理索引?如果是为了家庭作业,或者您出于某种原因正在实现数据结构,那么使用数组或自定义lin会更有意义ked列表实现作为备份存储,而不是使用内置的数据结构来处理索引和元素移动并忽略该行为。这是我的家庭作业。只是在这一点上卡住了,需要一点指导才能前进。只是尝试了更改一些内容,但仍然会出现一些错误。java er中这样说ror.Symbol T找不到Symbol