Ejemplo n.º 1
0
        static void Main(string[] args)

        {
            //nodes count for test
            DateTime start  = DateTime.Now;
            int      length = 7;

            //first node
            ListNode head = new ListNode();
            ListNode tail = new ListNode();
            ListNode temp = new ListNode();

            head.Data = rand.Next(0, 1000).ToString();
            tail      = head;

            for (int i = 1; i < length; i++)
            {
                tail = addNode(tail);
            }
            temp = head;

            //add ref to Random node
            for (int i = 0; i < length; i++)
            {
                temp.Rand = randomNode(head, length);
                temp      = temp.Next;
            }

            //declare first List

            ListRand first = new ListRand();

            first.Head  = head;
            first.Tail  = tail;
            first.Count = length;

            //serialize it

            FileStream fs = new FileStream("dat.dat", FileMode.OpenOrCreate);

            first.Serialize(fs);

            //deserialize in second List

            ListRand second = new ListRand();

            try
            {
                fs = new FileStream("dat.dat", FileMode.Open);
            }

            catch (Exception e)

            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Press Enter to exit.");
                Console.Read();
                Environment.Exit(0);
            }

            second.Deserialize(fs);

            //if second.Tail`s data equals first.Tail`s data, we guess it`s OK
            if (second.Tail.Data == first.Tail.Data)
            {
                Console.WriteLine("Success");
            }

            TimeSpan duration = DateTime.Now - start;

            Console.WriteLine("That took " + duration.TotalMilliseconds + " ms");

            Console.Read();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //nodes count for test
            int length = 7;

            //first node
            ListNode head = new ListNode();
            ListNode tail = new ListNode();
            ListNode temp = new ListNode();

            head.Data = rand.Next(0,1000).ToString();

            tail = head;

            for (int i = 1; i < length; i++)
                tail = addNode(tail);

            temp = head;

            //add ref to Random node
            for (int i = 0; i < length; i++)
            {
                temp.Rand = randomNode(head, length);
                temp = temp.Next;
            }

            //declare first List
            ListRand first = new ListRand();
            first.Head = head;
            first.Tail = tail;
            first.Count = length;

            //serialize it
            FileStream fs = new FileStream("dat.dat", FileMode.OpenOrCreate);
            first.Serialize(fs);

            //deserialize in second List
            ListRand second = new ListRand();
            try
            {
                fs = new FileStream("dat.dat", FileMode.Open);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Press Enter to exit.");
                Console.Read();
                Environment.Exit(0);
            }
            second.Deserialize(fs);

            //if second.Tail`s data equals first.Tail`s data, we guess it`s OK
            if (second.Tail.Data == first.Tail.Data) Console.WriteLine("Success");
            Console.Read();
        }