首页 文章

在树形图中设置树形图的值?

提问于
浏览
0

请耐心等待,我一整天都在网上搜索,试图找到正在发生的轻微问题的正确语法 . 如何在树形图中设置树形图?

Map 的实例变量是:

private final TreeMap<Integer,TreeMap<Integer,Double>> matrix;

/**
 * Change the value at a given position.
 * If the position is not in the matrix (i.e., i is not between 0 and rows-1
 * and j is not between 0 and cols-1), then don't change anything.
 *
 * @param i The row.
 * @param j The column.
 * @param v The new value.
 */
public void set(int i, int j, double v) {
    if (matrix.containsKey(i) && matrix.containsValue(j) == true) {
        matrix.remove(j); // Is this needed?
        matrix.put(i<j,v>); // ERROR: not right syntax for this 
    }
} // end of set method

2 回答

  • 0

    这是你要找的吗?

    matrix.get(i).put(j, v);
    
  • 2
    private final TreeMap<Integer,TreeMap<Integer,Double>> matrix;
    

    您不能将值声明为声明为final的实例,而不是在声明它的语句中:

    public final TreeMap<Integer,TreeMap<Integer,Double>> matrix  = new TreeMap<>();
    

    然后你应该像往常一样从 matrixputget TreeMap

    matrix.put(1, new TreeMap<Integer, Double>());
    matrix.get(1).put(1, 1.23);
    

相关问题