public void Add(T item) { BinFa <T> addFa = this; BinFa <T> newFa = new BinFa <T>(item); int ii = item.CompareTo(addFa.Root.Core); //other = addFa; Console.WriteLine(addFa.Root.Core); if (ii < 0) { if (addFa.Next(false) == null) { newFa.Insert(false, item); addFa.Add(item); } else { addFa = addFa.Next(false); } } else if (ii > 0) { if (addFa.Next(true) == null) { newFa.Insert(true, item); addFa.Add(item); } else { addFa = addFa.Next(false); } } }
public void Add2(T item) { BinFa <T> insertFa = this; Node <T> p = new Node <T>(item); int ii = item.CompareTo(insertFa.Root.Core); if (ii < 0) { RootRight(p); } else { RootLeft(p); } }
public BinFa <T> Next(bool isRight) { BinFa <T> fa; if (isRight) { fa = new BinFa <T>(Root.Right); } else { fa = new BinFa <T>(Root.Left); } return(fa); }
static void Main(string[] args) { string item = "kutya"; BinFa <string> binFa = new BinFa <string>(item); //binFa.Insert(true, "almafa"); //binFa.Insert(false, "körtefa"); //binFa.Insert(false, "diofa"); //binFa.Insert(true, "szilvafa"); //binFa.Insert(false, "fügefa"); binFa.Add2("almafa"); binFa.Add2("körtefa"); binFa.Add2("diofa"); binFa.Add2("szilvafa"); binFa.Add2("fügefa"); binFa.Add2("meggyfa"); binFa.Print(); Console.ReadKey(); }
public void Print() { BinFa <T> printFa = this; BinFa <T> otherFa; if (printFa == null) { return; } Console.WriteLine(Root.Core); otherFa = printFa; if (printFa.Root.Left != null) { printFa = printFa.Next(false); printFa.Print(); } printFa = otherFa; if (printFa.Root.Right != null) { printFa = printFa.Next(true); printFa.Print(); } }