Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何迭代自定义类的优先级队列_Android - Fatal编程技术网

Android 如何迭代自定义类的优先级队列

Android 如何迭代自定义类的优先级队列,android,Android,嗨,我正在开发一个蛇游戏,我想把蛇的移动点存储在一个优先队列中,但我不知道如何遍历这个优先队列 下面是我存储点的优先级队列类和点类 优先级队列类别: public class PriorityQueue { private Points[] heap; private int heapSize,capacity; /** Constructor **/ public PriorityQueue(){ heapSize = 0; }

嗨,我正在开发一个蛇游戏,我想把蛇的移动点存储在一个优先队列中,但我不知道如何遍历这个优先队列 下面是我存储点的优先级队列类和点类

优先级队列类别:

 public class PriorityQueue {

    private Points[] heap;
    private int heapSize,capacity;
    /** Constructor **/
    public PriorityQueue(){
        heapSize = 0;

    }
    public void setCapacity( int capacity)

    {
        this.capacity = capacity + 1;
        heap = new Points[this.capacity];

    }
    /** function to clear **/
    public void clear()
    {
        heap = new Points[capacity];
        heapSize = 0;

    }
    /** function to check if empty **/
    public boolean isEmpty()
    {
        return heapSize == 0;
    }
    /** function to check if full **/
    public boolean isFull()
    {

        return heapSize == capacity - 1;
    }

    /** function to get Size **/
    public int size()
    {
        return heapSize;
    }

    // method to insert point

    public void insert(float x, float y, float rotation, int priority)
    {

        Points points = new Points(x,y,rotation,priority);
        heap [++heapSize] = points;

        int pos = heapSize;
        while (pos != 1 && points.priority > heap[pos/2].priority)
        {
            heap[pos] = heap[pos/2];
            pos /=2;
        }
        heap[pos] = points;

    }

    // function to remove point

    public Points remove()
    {
        int parent, child;
        Points item, temp;
        if (isEmpty() )
        {
            System.out.println("Heap is empty");
            return null;
        }
        item = heap[1];
        temp = heap[heapSize--];
        parent = 1;
        child = 2;
        while (child <= heapSize)
        {
            if (child < heapSize && heap[child].priority < heap[child + 1].priority)
                child++;
            if (temp.priority >= heap[child].priority)
                break;

            heap[parent] = heap[child];
            parent = child;
            child *= 2;
        }
        heap[parent] = temp;
        return item;
    }
}
请指导我如何迭代这个队列类。 先谢谢你

public class Points {

    private float X;
    private float Y;
    int priority;
    private float rotation;

   public Points(float x, float y,float rotation,int priority)
   {

       this.X = x;
       this.Y = y;
       this.rotation = rotation;
       this.priority = priority;


   }

    public float getX() {
        return X;
    }

    public float getY() {
        return Y;
    }

    public float getRotation() {
        return rotation;
    }

    public int getPriority() {
        return priority;
    }
}