Hullo,
I've followed your advice by looking at the algorithm for deletion. Ur right regardless of the language the implementation should be similar.
Here's what I've broken it down to.
For the sake of brevity I am using integers to illustrate my point, however, in my actual assinement I will need to use actual names. Since the names will be cast as strings, direct comparison of their size will be possible. By size I mean, alphabetical precidance.
Most of this i red of the net:
Deletion
The algorithm must ensure that when the node is deleted from the tree, the ordering of the binary tree is kept intact.
Special Cases that have to be considered:
1)The node to be deleted has no children.
In this case the node may simply be deleted from the tree.
Before deletion of 2
3
/ \
2 7
After deletion of 2
3
\
7
2)The node has one child.
The child node is appended to the parent of the node to be deleted.
Before deletion of 2
4
/ \
2 7
\
3
After deletion of 2
4
/ \
3 7
3)The node to be deleted has two children.
The algorithm must determine which node to use in place of the node to be deleted:
i)Use the inorder successor of the node to be deleted.
Before Deletion of 5
7
/ \
5 8
/ \
3 6
/ /
1 4
After deletion of 5
7
/ \
4 8
/ \
3 6
/
1
ii)Else if no right subtree exists replace the node to be deleted with the it's left child.
Deletion before 5
7
/ \
5 8
/ \
3 6
/
1
Deletion after 5
7
/ \
3 8
/ \
1 6
Deletion of the root node is also a special case. I think.
And that's it. Although the integers would be names instead.
Best way to sort them is to do an insertion sort, sorting them during insertion.
I think the whole idea of my teacher giving me this assinement is to show that the names can be sorted in alphabetical order using 'in-order' traversal, or at least that what I was assuming.
I've not much experience with trees in my line of work
Perhaps it's time to dust of those books and help me out.
How would I put that into code?