Package bst

Examples of bst.BSTree


    while ((ch = System.in.read()) != 10) {
      sb.append((char) ch);
    }
    String[] input = sb.toString().split(";");

    BSTree tree = new BSTree();
    tree.create_empty();
   
    for (int i = 0; i < input.length; ++i) {
      String[] rational = input[i].split("/");
      Rational rat = null;
      if(rational.length==2)
        rat = new Rational(Integer.parseInt(rational[0]), Integer.parseInt(rational[1]));
     
      if(rational.length == 1)
        rat = new Rational(Integer.parseInt(rational[0]), 1);
     
      if(rat != null)
        tree.insert(rat);
    }
   
    System.out.println(tree.inord_transverse());
  }
View Full Code Here


public class TestBinarySearchTree {

  @Test
  public void testCreateEmptyGivesEmpty() {
    BSTree tree = new BSTree();
    tree.create_empty();
   
    boolean expected = true;
    boolean actual = tree.is_empty();
   
    assertEquals(expected, actual);
  }
View Full Code Here

    assertEquals(expected, actual);
  }
 
  @Test
  public void testInsertGivesNotEmpty(){
    BSTree tree = new BSTree();
    tree.create_empty();
   
    tree.insert(2.345);
   
    boolean expected = false;
    boolean actual = tree.is_empty();
   
    assertEquals(expected, actual);
  }
View Full Code Here

    assertEquals(expected, actual);
  }
 
  @Test
  public void testInordTransverseAddingOne(){
    BSTree tree = new BSTree();
    tree.create_empty();
   
    tree.insert(2.345);
   
    String expected = "2.345";
    String actual = tree.inord_transverse();
   
    assertEquals(expected, actual);
  }
View Full Code Here

    assertEquals(expected, actual);
  }
 
  @Test
  public void testInordTransverseAddingTwo(){
    BSTree tree = new BSTree();
    tree.create_empty();
   
    tree.insert(2.345);
    tree.insert(4.5622);
   
    String expected = "2.345 - 4.5622";
    String actual = tree.inord_transverse();
   
    assertEquals(expected, actual);
  }
View Full Code Here

    assertEquals(expected, actual);
  }
 
  @Test
  public void testInordTransverseAddingThree(){
    BSTree tree = new BSTree();
    tree.create_empty();
   
    tree.insert(2.345);
    tree.insert(4.5622);
    tree.insert(1.456);
   
    String expected = "1.456 - 2.345 - 4.5622";
    String actual = tree.inord_transverse();
   
    assertEquals(expected, actual);
  }
View Full Code Here

    assertEquals(expected, actual);
  }
 
  @Test
  public void testInordTransverseAddingFour(){
    BSTree tree = new BSTree();
    tree.create_empty();
   
    tree.insert(2.345);
    tree.insert(4.5622);
    tree.insert(1.456);
    tree.insert(0);
   
    String expected = "0.0 - 1.456 - 2.345 - 4.5622";
    String actual = tree.inord_transverse();
   
    assertEquals(expected, actual);
   
    tree.create_empty();
   
    tree.insert(2.345);
    tree.insert(4.5622);
    tree.insert(1.456);
    tree.insert(5);
   
    expected = "1.456 - 2.345 - 4.5622 - 5.0";
    actual = tree.inord_transverse();
   
    assertEquals(expected, actual);
  }
View Full Code Here

TOP

Related Classes of bst.BSTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.