Exemple #1
0
        static void Main(string[] args)
        {
            Stopwatch             stopwatch = new Stopwatch();
            MyLinkedList <string> list      = new MyLinkedList <string>();

            list.Add("Дмитрий");
            stopwatch.Start();
            string name = list.Current.Value;

            stopwatch.Stop();
            TimeSpan time = stopwatch.Elapsed;

            Console.WriteLine(time.TotalMilliseconds);
            Console.Read();
        }
Exemple #2
0
        // Main Method
        public static void Main()
        {
            /* Start with the empty list. */
            MyLinkedList list = new MyLinkedList();

            // Insert the values
            list.Insert(1);
            list.Insert(2);
            list.Insert(3);
            list.Insert(4);
            list.Insert(5);
            list.Insert(6);
            list.Insert(7);
            list.Insert(8);

            // Print the LinkedList
            list.PrintList();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            MyLinkedList <int> list = new MyLinkedList <int>();
            var first = list.AddLast(5);
            var node  = list.AddLast(2);
            var last  = list.AddLast(3);

            //list.RemoveFirst();
            //list.RemoveFirst();
            list.Clear();
            //list.AddAfter(node, 5555);
            //list.AddAfter(last, 666);
            //list.AddAfter(first, 33);
            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
            //Console.WriteLine(list.Contains(2));
        }
Exemple #4
0
        static void Main(string[] args)
        {
            MyLinkedList <int> l = new MyLinkedList <int>();

            l.Push_Back(5);
            l.Push_Front(4);
            l.Push_Back(6);
            l.Push_Front(3);
            l.Push_Front(2);
            l.Push_Back(7);
            l.Push_Front(1);

            Console.WriteLine("First element: " + l.Pop_Front().Value);

            l.Display();


            Console.ReadLine();
        }
Exemple #5
0
            public static void AppendList(MyLinkedList aList, ref MyLinkedList bList)
            {
                Link previous = new Link();
                Link next     = new Link();

                //add from
                Link ptr = bList.Head;
                //add to
                Link last = aList.Tail;


                //while(ptr.Next!=null)
                //{
                //    aList.InsertTail(ptr.Value);
                //    ptr = ptr.Next;

                //}

                do
                {
                    aList.InsertTail(ptr.Value);
                    ptr = ptr.Next;
                }while (ptr != null);

                //for (int i = 0; i < bList.Count; i++)
                //{


                //    aList.InsertTail(ptr.Value);


                //    //ptr = ptr.Next;
                //    //if (last != null)
                //    //    last = last.Next;

                //    //last.Next = ptr;
                //    ////ptr.Next = last;

                //    //ptr = ptr.Next;


                //}
            }
        static void Main(string[] args)
        {
            MyLinkedList<int> list = new MyLinkedList<int>();
            var first = list.AddLast(5);
            var node = list.AddLast(2);
            var last = list.AddLast(3);

            //list.RemoveFirst();
            //list.RemoveFirst();
            list.Clear();
            //list.AddAfter(node, 5555);
            //list.AddAfter(last, 666);
            //list.AddAfter(first, 33);
            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
            //Console.WriteLine(list.Contains(2));
        }
Exemple #7
0
        static void Main(string[] args)
        {
            Node node1 = new Node(1);
            Node node2 = new Node(2);
            Node node3 = new Node(3);
            Node node4 = new Node(4);
            //node1.Next = node2;
            //node2.Next = node3;

            MyLinkedList list = new MyLinkedList(null);

            list.Insert(node3);
            list.Insert(node2);
            list.Insert(node1);
            //list.Append(5);
            //list.InsertBefore(node2, 7);
            list.InsertAfter(node3, 7);

            list.Print();
        }
Exemple #8
0
        public MyLinkedList SumLists(Node HeadFirst, Node HeadSecond)
        {
            if (HeadFirst == null && HeadSecond == null)
            {
                return(null);
            }
            MyLinkedList list = new MyLinkedList(null);
            int          sum = 0; int overflow = 0;

            while (HeadFirst != null && HeadSecond != null)
            {
                sum = HeadFirst.Value + HeadSecond.Value + overflow;
                list.AddNodeAtEnd(new Node(null, sum % 10));
                overflow   = sum / 10;
                HeadFirst  = HeadFirst.Next;
                HeadSecond = HeadSecond.Next;
            }

            if (HeadFirst == null)
            {
                while (HeadSecond != null)
                {
                    sum = overflow + HeadSecond.Value;
                    list.AddNodeAtEnd(new Node(null, sum % 10));
                    overflow   = sum / 10;
                    HeadSecond = HeadSecond.Next;
                }
            }
            if (HeadSecond == null)
            {
                while (HeadFirst != null)
                {
                    sum = overflow + HeadFirst.Value;
                    list.AddNodeAtEnd(new Node(null, sum % 10));
                    overflow  = sum / 10;
                    HeadFirst = HeadFirst.Next;
                }
            }
            return(list);
        }
        public static void Main()
        {
            var linkedList = new MyLinkedList<int>();
            linkedList.Add(1);
            linkedList.Add(2);
            linkedList.Add(3);
            linkedList.Add(4);
            linkedList.Add(5);
            linkedList.Add(6);

            // Add
            Console.WriteLine("All nodes: ");
            ListAllNodes(linkedList);

            // Contains
            Console.WriteLine("Contains 4? : {0}", linkedList.Contains(4));
            Console.WriteLine("Contains 7? : {0}", linkedList.Contains(7));

            // Remove
            Console.WriteLine("All nodes after removing the first one: ");
            linkedList.Remove(1);
            ListAllNodes(linkedList);
        }
        public static void Main()
        {
            var linkedList = new MyLinkedList <int>();

            linkedList.Add(1);
            linkedList.Add(2);
            linkedList.Add(3);
            linkedList.Add(4);
            linkedList.Add(5);
            linkedList.Add(6);

            // Add
            Console.WriteLine("All nodes: ");
            ListAllNodes(linkedList);

            // Contains
            Console.WriteLine("Contains 4? : {0}", linkedList.Contains(4));
            Console.WriteLine("Contains 7? : {0}", linkedList.Contains(7));

            // Remove
            Console.WriteLine("All nodes after removing the first one: ");
            linkedList.Remove(1);
            ListAllNodes(linkedList);
        }
        static void Main(string[] args)
        {
            MyLinkedList <int> list = new MyLinkedList <int>();

            list.InsertAfter(11);
            list.InsertFirst(5);
            list.InsertFirst(6);
            list.InsertFirst(7);
            list.InsertAfter(1);
            list.InsertAfter(81);
            list.InsertAfter(10);
            list.InsertAfter(-1);

            list.DeleteFirst();
            list.DeleteAfter();


            Node <int> node = list.GetNode(7);

            if (node == null)
            {
                Console.WriteLine("Element is  apsent");
            }
            else
            {
                Console.WriteLine("Elemetn  is   present");
            }



            Console.WriteLine("Lenght =  {0}", list.length);



            Console.ReadKey();
        }
 private static void ListAllNodes(MyLinkedList<int> list)
 {
     Console.WriteLine(String.Join(", ", list.GetAllNodes()));
 }
Exemple #13
0
        static void Main(string[] args)
        {
            #region Create Instance
            IntNode      node  = new IntNode(50);
            IntNode      nodeX = new IntNode(5);
            MyLinkedList list  = new MyLinkedList();
            #endregion

            #region Implement LinkedList
            list.AddFirst(node);
            list.AddLast(node);
            list.Input();
            list.ShowList();
            Console.WriteLine();

            if (list.FindX(nodeX))
            {
                Console.WriteLine("Find X in List");
            }
            else
            {
                Console.WriteLine("Not find X in List");
            }
            IntNode x = list.GetMax();
            IntNode y = list.GetMin();
            Console.WriteLine("Max Node: " + x.Data);
            Console.WriteLine("Min Node: " + y.Data);

            Console.WriteLine("Even node in List");
            list.GetEvenList();
            Console.WriteLine("Odd node in List");
            list.GetOddList();

            list.SortNode();
            Console.WriteLine("List have been sorted");
            list.ShowList();
            Console.WriteLine();

            list.RemoveAtPos(3);
            Console.WriteLine("After remove at positon from list");
            list.ShowList();
            Console.WriteLine();

            list.RemoveX(5);
            Console.WriteLine("After remove X from list");
            list.ShowList();
            Console.WriteLine();

            list.InsertAt(3, 10);
            Console.WriteLine("Insert new node at pos with the value X in list");
            list.ShowList();
            Console.WriteLine();

            list.InsertAfterMin(4);
            Console.WriteLine("Insert new node after min node");
            list.ShowList();
            Console.WriteLine();

            list.InsertBeforeMax(65);
            Console.WriteLine("Insert new node before max node");
            list.ShowList();
            Console.WriteLine();

            list.InsertXAfterY(99, 30);
            Console.WriteLine("Insert new node after Y");
            list.ShowList();
            Console.WriteLine();

            list.InsertXBeforeY(99, 30);
            Console.WriteLine("Insert new node after Y");
            list.ShowList();
            Console.WriteLine();
            #endregion
        }
 private static void ListAllNodes(MyLinkedList <int> list)
 {
     Console.WriteLine(String.Join(", ", list.GetAllNodes()));
 }
Exemple #15
0
        Point current; //текущий


        public MyNumerator(MyLinkedList collection)
        {
            beg     = collection.Begin;
            current = null;
        }
Exemple #16
0
 public Enumerator(MyLinkedList <T> myList)
 {
     list = myList;
 }