How to delete the whole binary search tree?
- From: SamuelXiao <foolsmart2005@xxxxxxxxx>
- Date: Wed, 15 Oct 2008 23:14:51 -0700 (PDT)
In my program, a list of customers records are read from a file. I
have to store them in a binary search tree. By far, I can read the
file records, store them in a tree. However, if the program read a
new file, the customers records in the new file should replacing the
information read before. e.g. cust1.txt is read first, cust2.txt read
second, the tree should delete all the records from file 1 and then
read the records from tree2 and store them. In this case, I only use
one BStree, t1, to store the records. I write a deltree methods but
it doesn't work.
-------------------Here is my code-----------------------------
// in the read file method
public static void Readfile(Bst inputtree){
if(!inputtree.isEmpty()){
deltree(inputtree);
inputtree = new Bst();
}
//..........
}
public static Bst deltree(Bst inputtree){
if(inputtree.getRoot()==null) return;
deltreeNode(inputtree.getRoot());
}
public static void deltreeNode(BTNode inputNode){
if(inputNode!=null){
deltreeNode(inputNode.getLeft());
deltreeNode(inputNode.getRight());
inputNode = null;
}
}
-----------------------------------------------------------------------------
But, when I test it, it seems that the t1 doesn't be deleted, the
information stored in it still stay and the new records read from a
new file doesn't replace it. How can I do that in Binary tree.
for example,
cust1.txt ----------id: 18 34 35
cust2.txt ----------id: 30 45 11
after excuting the program, i input cust1.txt first and then show the
records in the t1, it shows me the correct answer. Then, i recall
readfile() again, input cust2.txt, it doesn't replace records in t1.
when showing the records, it still the cust1.txt 's information
instead of cust2.txt. How to implement delete the whole tree so that
I can store new records?
.
- Follow-Ups:
- Re: How to delete the whole binary search tree?
- From: GArlington
- Re: How to delete the whole binary search tree?
- From: Dirk Michaelsen
- Re: How to delete the whole binary search tree?
- Prev by Date: Re: model "1.5" CRUD (update)
- Next by Date: Re: How to delete the whole binary search tree?
- Previous by thread: Where to find the source code for tools.jar
- Next by thread: Re: How to delete the whole binary search tree?
- Index(es):
Relevant Pages
|