如何在Priority Queue Java中更新对象属性?

时间:2018-10-21 23:53:32

标签: java data-structures priority-queue

如果我有一个具有四个属性的类以及它们的getter和setter:

function factorial(n) {
  // terminate the recursion once we hit zero
  if (n === 0) { return 1;}
  // otherwise keep calling the function recursively 
  else {return factorial(n - 1) * n;}
}

let f = factorial(4);
console.log(f)

在我的主类中,我有一个PriorityQueue,其形状按高度排序。我的问题是:如何在PriorityQueue中找到对象并更新其长度和宽度?

public class Shape {

    private int id;
    private int length;
    private int width;
    private int height;

    Shape(int id, int length, int width, int height){
        this.id = id;
        this.length = length;
        this.width = width;
        this.height = height;
    }

    public int getId() {
        return id;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

}

PS:我必须将其实现为PriorityQueue

0 个答案:

没有答案