Removed whitespace and altered program to allow for constant node removal for tests
This commit is contained in:
parent
006cd9a00a
commit
579b3dc0de
@ -15,16 +15,18 @@ namespace BinaryTree
|
|||||||
tree.Add(random.Next(0, 100));
|
tree.Add(random.Next(0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
tree.Print(tree.Root);
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
Console.Clear();
|
||||||
|
tree.Print(tree.Root);
|
||||||
Console.WriteLine("-------------------------------------");
|
Console.WriteLine("-------------------------------------");
|
||||||
Console.WriteLine("Delete node: ");
|
Console.WriteLine("Delete node: ");
|
||||||
|
|
||||||
tree.Delete(Convert.ToInt32(Console.ReadLine()));
|
tree.Delete(Convert.ToInt32(Console.ReadLine()));
|
||||||
|
|
||||||
tree.Print(tree.Root);
|
tree.Print(tree.Root);
|
||||||
|
Console.ReadLine();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -100,13 +100,6 @@ namespace BinaryTree
|
|||||||
Current.Data = temp.Data;
|
Current.Data = temp.Data;
|
||||||
|
|
||||||
//Find if the temp node is a left or a right now before deleting.
|
//Find if the temp node is a left or a right now before deleting.
|
||||||
//Adopt subtree Nodes// -- Subtrees are lost (If temp node is only 1 level down, data is lost)
|
|
||||||
// if (temp.GetLeft() != null)
|
|
||||||
// {
|
|
||||||
// temp.GetParent().SetRight(temp.GetLeft());
|
|
||||||
// }else{
|
|
||||||
// temp.GetParent().SetRight(null);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
if(temp.GetParent() == Current){
|
if(temp.GetParent() == Current){
|
||||||
@ -121,6 +114,12 @@ namespace BinaryTree
|
|||||||
temp.GetParent().SetRight(null);
|
temp.GetParent().SetRight(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//*Code not currently working - Doesn't confidently replace the root or parent nodes of each item that is deleted
|
||||||
|
// temp.SetParent(Current.GetParent());
|
||||||
|
// if (Current.GetParent() == null)
|
||||||
|
// {
|
||||||
|
// Root = Current;
|
||||||
|
// }
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
@ -139,7 +138,7 @@ namespace BinaryTree
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Current.Data < Current.GetParent().Data)
|
if (Current == Root || Current.Data < Current.GetParent().Data)
|
||||||
{
|
{
|
||||||
LeftFlag = true;
|
LeftFlag = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user