static void Main(string[] args)
        {
            int[] dataarray = { 1, 2, 3, 4, 5, 6, 7 };

            treeresult t = new treeresult();

            t.head = createTreeFromArray(dataarray, t.head, 0);

            BFS(t);

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static string serializeTree(treeresult pt, string ser)
        {
            Queue <points> q = new Queue <points>();

            q.Enqueue(pt.head);

            while (q.Count > 0)
            {
                points node = new points();
                node = q.Dequeue();
                ser += node.data.ToString() + ",";

                if (node.data == 999)
                {
                    continue;
                }

                if (node.lside != null)
                {
                    q.Enqueue(node.lside);
                }
                else
                {
                    points p1 = new points(999);
                    q.Enqueue(p1);
                }


                if (node.rside != null)
                {
                    q.Enqueue(node.rside);
                }
                else
                {
                    points p1 = new points(999);
                    q.Enqueue(p1);
                }
            }

            return(ser);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            int[] dataarray = { 1, 2, 3, 4, 5, 6, 7 };

            treeresult t = new treeresult();

            t.head = createTreeFromArray(dataarray, t.head, 0);

            //BFS(t);

            string answer = String.Empty;

            answer = serializeTree(t, answer);
            Console.WriteLine(answer);

            treeresult deserT = new treeresult();

            deserT.head = deserializetotree(answer, deserT.head, 0);

            BFS(deserT);
            Console.ReadLine();
        }
        static void BFS(treeresult pt)
        {
            Queue <points> q = new Queue <points>();

            q.Enqueue(pt.head);

            while (q.Count > 0)
            {
                points node = new points();
                node = q.Dequeue();
                Console.Write(node.data);

                if (node.lside != null)
                {
                    q.Enqueue(node.lside);
                }

                if (node.rside != null)
                {
                    q.Enqueue(node.rside);
                }
            }
        }