How to delete the whole binary search tree?



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?
.



Relevant Pages

  • Re: Parsing and storing formulas
    ... you could easily store different views/stored ... >I was wondering how I can parse a mathematical formula in a storable way. ... > be stored for in the database. ... > The second idea is to represent the formula as a tree. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to delete the whole binary search tree?
    ... have to store them in a binary search tree. ... So i write the makeEmpty() member function to do it. ...
    (comp.lang.java.help)
  • Re: How to delete the whole binary search tree?
    ... have to store them in a binary search tree. ... public static void Readfile(Bst inputtree){ ...
    (comp.lang.java.help)
  • Re: Deleting a node from TreeView
    ... to store the states, but I'm not sure its worth the effort. ... products on Windows 2000 and some Windows NT systems with 2000 libraries. ... This allows you to open the tree in any state you want it. ... > in a treeview control I'd be eternally grateful! ...
    (microsoft.public.access.formscoding)
  • Is there a better way to store this?
    ... The thing is this tree needs to be stored to and loaded from disk. ... I figure the best way to do this is to store the CLOS tree ... ;;; At the leaf nodes are animals. ... (defgeneric store (class stream)) ...
    (comp.lang.lisp)