Untitled
deletionunknown
plain_text
3 years ago
2.2 kB
5
Indexable
public static void main(String[] args) { //test data [c , f, a, d, e,b] check_deletion(); } public static void pop(StaffBST tree, String[] lst){ for (String name : lst) { Employee nw_employee= new Employee(name,"x"); tree.put(nw_employee); } } public static StaffBST init_data(boolean dis){ String[] test_data = {"c" , "f", "a", "d", "e","b"}; if(dis){ System.out.println("This is the test data:"); System.out.println(Arrays.toString(test_data)); } StaffBST testTree = new StaffBST(); pop(testTree,test_data); return testTree; } public static void check_deletion(){ String[] test_data = {"c" , "f", "a", "d", "e","b"}; StaffBST Testree = init_data(true); StaffBST Testree_copy = init_data(false); System.out.println("Deletion test function"); for( String element: test_data){ List<String> cop = new ArrayList<>(); Testree.travel(root,cop); System.out.println("before deletion:"); System.out.println(cop); Testree.remove(element); cop.clear(); //// Testree.travel(root,cop); System.out.println("after deletion:"+" name:"+element +" removed"); System.out.println(cop); //Testree.spec(root,element); } //check deletion one node } public void travel(Node tree,List<String> lst) { //inOrder if (tree == null) { return; } travel(tree.left,lst); System.out.println(tree.data); lst.add(tree.data.getName()); travel(tree.right,lst); // to do } public void spec(Node tree,String name) { //inOrder if (tree == null) { return; } spec(tree.left,name); if(tree.data.getName().compareTo(name)==0){ System.out.println("Failure:leaf node not deleted"); } spec(tree.right,name); // to do }
Editor is loading...