Beispiel #1
0
 public void InorderPrint(StringBuilder sb)
 {
     foreach (string name in names)
     {
         sb.AppendLine(name);
     }
     if (Upper != null)
     {
         Upper.InorderPrint(sb);
     }
     if (Middle != null)
     {
         Middle.InorderPrint(sb);
     }
     if (Lower != null)
     {
         Lower.InorderPrint(sb);
     }
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            int cases = Convert.ToInt32(Console.ReadLine());

            while (cases > 0)
            {
                int       familymemcount = Convert.ToInt32(Console.ReadLine());
                CasteNode familyRoot     = new CasteNode();
                while (familymemcount > 0)
                {
                    string[] line      = Console.ReadLine().Split(' ');
                    string   name      = line[0].Trim(':');
                    string[] heirarchy = line[1].Split('-');
                    familyRoot.AddNode(name, heirarchy);
                    familymemcount--;
                }
                StringBuilder sb = new StringBuilder();
                familyRoot.InorderPrint(sb);
                Console.Write(sb.ToString());
                Console.WriteLine("==============================");
                cases--;
            }
            Console.ReadLine();
        }