Example #1
0
        static void Main(string[] args)
        {
            //linkedList2<int> list = new linkedList2<int>();
            Random rand = new Random(DateTime.Now.Millisecond);
            //int delitel = 10000 / 2;
            //for (int i = 0; i < 10000; i++)
            //{
            //    list.add(i % delitel);
            //}
            //list.deleteDoubles();
            //for (int i=0;i<10000000; i++)
            //{
            //    if (rand.Next(0, 20) > 10)
            //        list.add(i%20);
            //}
            //list.deleteDoublesHashTb();
            linkedList2 <int> list = new linkedList2 <int>();

            for (int i = 0; i < 1000; i++)
            {
                list.add(rand.Next(0, 200));
            }
            list.devideListByEl(50);
            for (int i = list.countOfElements - 1; i >= 0; i--)
            {
                Console.WriteLine(list.findElForOneLinkedListFromEnd_2pointerRealise(i).element);
            }
        }
Example #2
0
        public static listElement <T> findIntersection(linkedList2 <T> a, linkedList2 <T> b)
        {
            listElement <T> res = null;

            if (a.findElForOneLinkedListFromEnd_2pointerRealise(0) == b.findElForOneLinkedListFromEnd_2pointerRealise(0))
            {
                int             difference = 0;
                listElement <T> currentA   = a.findElForOneLinkedListFromEnd_2pointerRealise(a.countOfElements - 1);
                listElement <T> currentB   = b.findElForOneLinkedListFromEnd_2pointerRealise(b.countOfElements - 1);
                if (a.countOfElements >= b.countOfElements)
                {
                    difference = a.countOfElements - b.countOfElements;
                    while (difference > 0)
                    {
                        currentA = currentA.nextElement;
                        difference--;
                    }
                }
                else
                {
                    difference = b.countOfElements - a.countOfElements;
                    while (difference > 0)
                    {
                        currentB = currentB.nextElement;
                        difference--;
                    }
                }
                while (currentA != null && currentB != null)
                {
                    if (currentA == currentB)
                    {
                        res = currentA;
                        break;
                    }
                    currentA = currentA.nextElement;
                    currentB = currentB.nextElement;
                }
            }
            return(res);
        }