当前位置: 首页>>代码示例>>Java>>正文


Java AVLTree类代码示例

本文整理汇总了Java中org.apache.commons.math3.geometry.partitioning.utilities.AVLTree的典型用法代码示例。如果您正苦于以下问题:Java AVLTree类的具体用法?Java AVLTree怎么用?Java AVLTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AVLTree类属于org.apache.commons.math3.geometry.partitioning.utilities包,在下文中一共展示了AVLTree类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testInsert

import org.apache.commons.math3.geometry.partitioning.utilities.AVLTree; //导入依赖的package包/类
@Test
public void testInsert() {
    // this array in this order allows to pass in all branches
    // of the insertion algorithm
    int[] array = { 16, 13, 15, 14,  2,  0, 12,  9,  8,  5,
        11, 18, 19, 17,  4,  7,  1,  3,  6, 10 };
    AVLTree<Integer> tree = buildTree(array);

    Assert.assertEquals(array.length, tree.size());

    for (int i = 0; i < array.length; ++i) {
        Assert.assertEquals(array[i], value(tree.getNotSmaller(new Integer(array[i]))));
    }

    checkOrder(tree);

}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:AVLTreeTest.java

示例2: testDelete1

import org.apache.commons.math3.geometry.partitioning.utilities.AVLTree; //导入依赖的package包/类
@Test
public void testDelete1() {
    int[][][] arrays = {
        { { 16, 13, 15, 14, 2, 0, 12, 9, 8, 5, 11, 18, 19, 17, 4, 7, 1, 3, 6, 10 },
            { 11, 10, 9, 12, 16, 15, 13, 18, 5, 0, 3, 2, 14, 6, 19, 17, 8, 4, 7, 1 } },
            { { 16, 13, 15, 14, 2, 0, 12, 9, 8, 5, 11, 18, 19, 17, 4, 7, 1, 3, 6, 10 },
                { 0, 17, 14, 15, 16, 18,  6 } },
                { { 6, 2, 7, 8, 1, 4, 3, 5 }, { 8 } },
                { { 6, 2, 7, 8, 1, 4, 5 }, { 8 } },
                { { 3, 7, 2, 1, 5, 8, 4 }, { 1 } },
                { { 3, 7, 2, 1, 5, 8, 6 }, { 1 } }
    };
    for (int i = 0; i < arrays.length; ++i) {
        AVLTree<Integer> tree = buildTree(arrays[i][0]);
        Assert.assertTrue(! tree.delete(new Integer(-2000)));
        for (int j = 0; j < arrays[i][1].length; ++j) {
            Assert.assertTrue(tree.delete(tree.getNotSmaller(new Integer(arrays[i][1][j])).getElement()));
            Assert.assertEquals(arrays[i][0].length - j - 1, tree.size());
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:AVLTreeTest.java

示例3: testNavigation

import org.apache.commons.math3.geometry.partitioning.utilities.AVLTree; //导入依赖的package包/类
@Test
public void testNavigation() {
    int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    AVLTree<Integer> tree = buildTree(array);

    AVLTree<Integer>.Node node = tree.getSmallest();
    Assert.assertEquals(array[0], value(node));
    for (int i = 0; i < array.length; ++i) {
        Assert.assertEquals(array[i], value(node));
        node = node.getNext();
    }
    Assert.assertNull(node);

    node = tree.getLargest();
    Assert.assertEquals(array[array.length - 1], value(node));
    for (int i = array.length - 1; i >= 0; --i) {
        Assert.assertEquals(array[i], value(node));
        node = node.getPrevious();
    }
    Assert.assertNull(node);

    checkOrder(tree);

}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:25,代码来源:AVLTreeTest.java

示例4: testSearch

import org.apache.commons.math3.geometry.partitioning.utilities.AVLTree; //导入依赖的package包/类
@Test
public void testSearch() {
    int[] array = { 2, 4, 6, 8, 10, 12, 14 };
    AVLTree<Integer> tree = buildTree(array);

    Assert.assertNull(tree.getNotLarger(new Integer(array[0] - 1)));
    Assert.assertNull(tree.getNotSmaller(new Integer(array[array.length - 1] + 1)));

    for (int i = 0; i < array.length; ++i) {
        Assert.assertEquals(array[i],
                            value(tree.getNotSmaller(new Integer(array[i] - 1))));
        Assert.assertEquals(array[i],
                            value(tree.getNotLarger(new Integer(array[i] + 1))));
    }

    checkOrder(tree);

}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:AVLTreeTest.java

示例5: testRepetition

import org.apache.commons.math3.geometry.partitioning.utilities.AVLTree; //导入依赖的package包/类
@Test
public void testRepetition() {
    int[] array = { 1, 1, 3, 3, 4, 5, 6, 7, 7, 7, 7, 7 };
    AVLTree<Integer> tree = buildTree(array);
    Assert.assertEquals(array.length, tree.size());

    AVLTree<Integer>.Node node = tree.getNotSmaller(new Integer(3));
    Assert.assertEquals(3, value(node));
    Assert.assertEquals(1, value(node.getPrevious()));
    Assert.assertEquals(3, value(node.getNext()));
    Assert.assertEquals(4, value(node.getNext().getNext()));

    node = tree.getNotLarger(new Integer(2));
    Assert.assertEquals(1, value(node));
    Assert.assertEquals(1, value(node.getPrevious()));
    Assert.assertEquals(3, value(node.getNext()));
    Assert.assertNull(node.getPrevious().getPrevious());

    AVLTree<Integer>.Node otherNode = tree.getNotSmaller(new Integer(1));
    Assert.assertTrue(node != otherNode);
    Assert.assertEquals(1, value(otherNode));
    Assert.assertNull(otherNode.getPrevious());

    node = tree.getNotLarger(new Integer(10));
    Assert.assertEquals(7, value(node));
    Assert.assertNull(node.getNext());
    node = node.getPrevious();
    Assert.assertEquals(7, value(node));
    node = node.getPrevious();
    Assert.assertEquals(7, value(node));
    node = node.getPrevious();
    Assert.assertEquals(7, value(node));
    node = node.getPrevious();
    Assert.assertEquals(7, value(node));
    node = node.getPrevious();
    Assert.assertEquals(6, value(node));

    checkOrder(tree);

}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:41,代码来源:AVLTreeTest.java

示例6: buildTree

import org.apache.commons.math3.geometry.partitioning.utilities.AVLTree; //导入依赖的package包/类
private AVLTree<Integer> buildTree(int[] array) {
    AVLTree<Integer> tree = new AVLTree<Integer>();
    for (int i = 0; i < array.length; ++i) {
        tree.insert(new Integer(array[i]));
        tree.insert(null);
    }
    return tree;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:9,代码来源:AVLTreeTest.java

示例7: checkOrder

import org.apache.commons.math3.geometry.partitioning.utilities.AVLTree; //导入依赖的package包/类
private void checkOrder(AVLTree<Integer> tree) {
    AVLTree<Integer>.Node next = null;
    for (AVLTree<Integer>.Node node = tree.getSmallest();
    node != null;
    node = next) {
        next = node.getNext();
        if (next != null) {
            Assert.assertTrue(node.getElement().compareTo(next.getElement()) <= 0);
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:12,代码来源:AVLTreeTest.java


注:本文中的org.apache.commons.math3.geometry.partitioning.utilities.AVLTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。