C ++:使用std :: set查找BST的左右子级

时间:2019-05-12 08:55:07

标签: c++ set binary-search-tree stdset

据我所知,集合是基于二叉搜索树的抽象数据结构的。

如何像BST中那样找到集合中某个元素的左右子元素?

示例-

class Tuple implements Comparable<Tuple> {
        Object one;
        Object two;
        Object three;
        public Tuple(final Object one, final Object two, final Object three) {
            this.one = one;
            this.two = two;
            this.three = three;
        }
        @Override
        public int compareTo(final Tuple that) {
            // TODO: Do your comparison here for the fields one, two and three
            return 0;
        }
    }
    Map<Tuple, Object> mapKeyedByCompositeTuple = new HashMap<>();
    // TODO: Inside your loop
    for (int i = 10; i > 0; i--) {
        Tuple key = new Tuple("cell-one-value-" + i, "cell-two-value-" + i, "cell-three-value-" + i);
        mapKeyedByCompositeTuple.put(key, "cell-four-value-" + i);
    }
    System.out.println(mapKeyedByCompositeTuple);

如何在这里将其用作BST?

0 个答案:

没有答案