Example #1
0
        public void GedraagtMijnLinkedListZichNetZoAlsDieVanDotNet()
        {
            var ours = new LinkedList <int> {
                1, 2, 3, 4
            };
            var theirs = new System.Collections.Generic.LinkedList <int>();

            theirs.AddAfter(theirs.AddAfter(theirs.AddAfter(theirs.AddFirst(1), 2), 3), 4);

            Assert.Equal(theirs, ours);
        }
        /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */
        public void Dec(string key)
        {
            if (!_dict.ContainsKey(key))
            {
                return;
            }

            var ln = _dict[key];

            ln.Value.value--;
            if (ln.Value.value == 0)
            {
                _dict.Remove(key);
                _list.Remove(ln);
            }
            if (ln.Next != null && ln.Next.Value.value > ln.Value.value)
            {
                var n = ln.Next;
                _list.Remove(ln);
                while (n.Next != null && n.Next.Value.value > ln.Value.value)
                {
                    n = n.Next;
                }

                _list.AddAfter(n, ln);
            }
        }
Example #3
0
        static void Main()
        {
            var linked = new System.Collections.Generic.LinkedList <int>();
            var node   = new LinkedListNode <int>(1);

            linked.AddFirst(node);
            var x = linked.AddAfter(node, 5);

            var list = new LinkedList <int>()
            {
                1, 2, 3, 4
            };

            list.Print();
            list.Print();
            list.FindFirst(4);
            Console.Read();
        }
Example #4
0
            public void Add(int n, T t)
            {
                if (n == 0)
                {
                    if (Node != null)
                    {
                        Node.Value = t;
                    }
                    return;
                }

                Enumerator itr = new Enumerator(this);

                if (!itr.Move(n - Math.Sign(n)))
                {
                    if (begin)
                    {
                        List.AddFirst(t);
                    }
                    else
                    {
                        List.AddLast(t);
                    }

                    /*if (!itr.Move(-Math.Sign(n)))
                     * {
                     *  itr.Move(Math.Sign(n));
                     *  n *= -1;
                     * }*/
                }
                else
                {
                    if (n > 0)
                    {
                        List.AddAfter(itr.Node, t);
                    }
                    else if (n < 0)
                    {
                        List.AddBefore(itr.Node, t);
                    }
                }
            }
Example #5
0
    public void Populate()
    {
        #region Types of Keywords

        FieldPublicDynamic = new { PropPublic1 = "A", PropPublic2 = 1, PropPublic3 = "B", PropPublic4 = "B", PropPublic5 = "B", PropPublic6 = "B", PropPublic7 = "B", PropPublic8 = "B", PropPublic9 = "B", PropPublic10 = "B", PropPublic11 = "B", PropPublic12 = new { PropSubPublic1 = 0, PropSubPublic2 = 1, PropSubPublic3 = 2 } };
        FieldPublicObject  = new StringBuilder("Object - StringBuilder");
        FieldPublicInt32   = int.MaxValue;
        FieldPublicInt64   = long.MaxValue;
        FieldPublicULong   = ulong.MaxValue;
        FieldPublicUInt    = uint.MaxValue;
        FieldPublicDecimal = 100000.999999m;
        FieldPublicDouble  = 100000.999999d;
        FieldPublicChar    = 'A';
        FieldPublicByte    = byte.MaxValue;
        FieldPublicBoolean = true;
        FieldPublicSByte   = sbyte.MaxValue;
        FieldPublicShort   = short.MaxValue;
        FieldPublicUShort  = ushort.MaxValue;
        FieldPublicFloat   = 100000.675555f;

        FieldPublicInt32Nullable   = int.MaxValue;
        FieldPublicInt64Nullable   = 2;
        FieldPublicULongNullable   = ulong.MaxValue;
        FieldPublicUIntNullable    = uint.MaxValue;
        FieldPublicDecimalNullable = 100000.999999m;
        FieldPublicDoubleNullable  = 100000.999999d;
        FieldPublicCharNullable    = 'A';
        FieldPublicByteNullable    = byte.MaxValue;
        FieldPublicBooleanNullable = true;
        FieldPublicSByteNullable   = sbyte.MaxValue;
        FieldPublicShortNullable   = short.MaxValue;
        FieldPublicUShortNullable  = ushort.MaxValue;
        FieldPublicFloatNullable   = 100000.675555f;

        #endregion

        #region System

        FieldPublicDateTime         = new DateTime(2000, 1, 1, 1, 1, 1);
        FieldPublicTimeSpan         = new TimeSpan(1, 10, 40);
        FieldPublicEnumDateTimeKind = DateTimeKind.Local;

        // Instantiate date and time using Persian calendar with years,
        // months, days, hours, minutes, seconds, and milliseconds
        FieldPublicDateTimeOffset = new DateTimeOffset(1387, 2, 12, 8, 6, 32, 545,
                                                       new System.Globalization.PersianCalendar(),
                                                       new TimeSpan(1, 0, 0));

        FieldPublicIntPtr         = new IntPtr(100);
        FieldPublicTimeZone       = TimeZone.CurrentTimeZone;
        FieldPublicTimeZoneInfo   = TimeZoneInfo.Utc;
        FieldPublicTuple          = Tuple.Create <string, int, decimal>("T-string\"", 1, 1.1m);
        FieldPublicType           = typeof(object);
        FieldPublicUIntPtr        = new UIntPtr(100);
        FieldPublicUri            = new Uri("http://www.site.com");
        FieldPublicVersion        = new Version(1, 0, 100, 1);
        FieldPublicGuid           = new Guid("d5010f5b-0cd1-44ca-aacb-5678b9947e6c");
        FieldPublicSingle         = Single.MaxValue;
        FieldPublicException      = new Exception("Test error", new Exception("inner exception"));
        FieldPublicEnumNonGeneric = EnumTest.ValueA;
        FieldPublicAction         = () => true.Equals(true);
        FieldPublicAction2        = (a, b) => true.Equals(true);
        FieldPublicFunc           = () => true;
        FieldPublicFunc2          = (a, b) => true;

        #endregion

        #region Arrays and Collections

        FieldPublicArrayUni    = new string[2];
        FieldPublicArrayUni[0] = "[0]";
        FieldPublicArrayUni[1] = "[1]";

        FieldPublicArrayTwo       = new string[2, 2];
        FieldPublicArrayTwo[0, 0] = "[0, 0]";
        FieldPublicArrayTwo[0, 1] = "[0, 1]";
        FieldPublicArrayTwo[1, 0] = "[1, 0]";
        FieldPublicArrayTwo[1, 1] = "[1, 1]";

        FieldPublicArrayThree          = new string[1, 1, 2];
        FieldPublicArrayThree[0, 0, 0] = "[0, 0, 0]";
        FieldPublicArrayThree[0, 0, 1] = "[0, 0, 1]";

        FieldPublicJaggedArrayTwo    = new string[2][];
        FieldPublicJaggedArrayTwo[0] = new string[5] {
            "a", "b", "c", "d", "e"
        };
        FieldPublicJaggedArrayTwo[1] = new string[4] {
            "a1", "b1", "c1", "d1"
        };

        FieldPublicJaggedArrayThree          = new string[1][][];
        FieldPublicJaggedArrayThree[0]       = new string[1][];
        FieldPublicJaggedArrayThree[0][0]    = new string[2];
        FieldPublicJaggedArrayThree[0][0][0] = "[0][0][0]";
        FieldPublicJaggedArrayThree[0][0][1] = "[0][0][1]";

        FieldPublicMixedArrayAndJagged = new int[3][, ]
        {
            new int[, ] {
                { 1, 3 }, { 5, 7 }
            },
            new int[, ] {
                { 0, 2 }, { 4, 6 }, { 8, 10 }
            },
            new int[, ] {
                { 11, 22 }, { 99, 88 }, { 0, 9 }
            }
        };

        FieldPublicDictionary = new System.Collections.Generic.Dictionary <string, string>();
        FieldPublicDictionary.Add("Key1", "Value1");
        FieldPublicDictionary.Add("Key2", "Value2");
        FieldPublicDictionary.Add("Key3", "Value3");
        FieldPublicDictionary.Add("Key4", "Value4");

        FieldPublicList = new System.Collections.Generic.List <int>();
        FieldPublicList.Add(0);
        FieldPublicList.Add(1);
        FieldPublicList.Add(2);

        FieldPublicQueue = new System.Collections.Generic.Queue <int>();
        FieldPublicQueue.Enqueue(10);
        FieldPublicQueue.Enqueue(11);
        FieldPublicQueue.Enqueue(12);

        FieldPublicHashSet = new System.Collections.Generic.HashSet <string>();
        FieldPublicHashSet.Add("HashSet1");
        FieldPublicHashSet.Add("HashSet2");

        FieldPublicSortedSet = new System.Collections.Generic.SortedSet <string>();
        FieldPublicSortedSet.Add("SortedSet1");
        FieldPublicSortedSet.Add("SortedSet2");
        FieldPublicSortedSet.Add("SortedSet3");

        FieldPublicStack = new System.Collections.Generic.Stack <string>();
        FieldPublicStack.Push("Stack1");
        FieldPublicStack.Push("Stack2");
        FieldPublicStack.Push("Stack3");

        FieldPublicLinkedList = new System.Collections.Generic.LinkedList <string>();
        FieldPublicLinkedList.AddFirst("LinkedList1");
        FieldPublicLinkedList.AddLast("LinkedList2");
        FieldPublicLinkedList.AddAfter(FieldPublicLinkedList.Find("LinkedList1"), "LinkedList1.1");

        FieldPublicObservableCollection = new System.Collections.ObjectModel.ObservableCollection <string>();
        FieldPublicObservableCollection.Add("ObservableCollection1");
        FieldPublicObservableCollection.Add("ObservableCollection2");

        FieldPublicKeyedCollection = new MyDataKeyedCollection();
        FieldPublicKeyedCollection.Add(new MyData()
        {
            Data = "data1", Id = 0
        });
        FieldPublicKeyedCollection.Add(new MyData()
        {
            Data = "data2", Id = 1
        });

        var list = new List <string>();
        list.Add("list1");
        list.Add("list2");
        list.Add("list3");

        FieldPublicReadOnlyCollection = new ReadOnlyCollection <string>(list);

        FieldPublicReadOnlyDictionary           = new ReadOnlyDictionary <string, string>(FieldPublicDictionary);
        FieldPublicReadOnlyObservableCollection = new ReadOnlyObservableCollection <string>(FieldPublicObservableCollection);
        FieldPublicCollection = new Collection <string>();
        FieldPublicCollection.Add("collection1");
        FieldPublicCollection.Add("collection2");
        FieldPublicCollection.Add("collection3");

        FieldPublicArrayListNonGeneric = new System.Collections.ArrayList();
        FieldPublicArrayListNonGeneric.Add(1);
        FieldPublicArrayListNonGeneric.Add("a");
        FieldPublicArrayListNonGeneric.Add(10.0m);
        FieldPublicArrayListNonGeneric.Add(new DateTime(2000, 01, 01));

        FieldPublicBitArray    = new System.Collections.BitArray(3);
        FieldPublicBitArray[2] = true;

        FieldPublicSortedList = new System.Collections.SortedList();
        FieldPublicSortedList.Add("key1", 1);
        FieldPublicSortedList.Add("key2", 2);
        FieldPublicSortedList.Add("key3", 3);
        FieldPublicSortedList.Add("key4", 4);

        FieldPublicHashtableNonGeneric = new System.Collections.Hashtable();
        FieldPublicHashtableNonGeneric.Add("key1", 1);
        FieldPublicHashtableNonGeneric.Add("key2", 2);
        FieldPublicHashtableNonGeneric.Add("key3", 3);
        FieldPublicHashtableNonGeneric.Add("key4", 4);

        FieldPublicQueueNonGeneric = new System.Collections.Queue();
        FieldPublicQueueNonGeneric.Enqueue("QueueNonGeneric1");
        FieldPublicQueueNonGeneric.Enqueue("QueueNonGeneric2");
        FieldPublicQueueNonGeneric.Enqueue("QueueNonGeneric3");

        FieldPublicStackNonGeneric = new System.Collections.Stack();
        FieldPublicStackNonGeneric.Push("StackNonGeneric1");
        FieldPublicStackNonGeneric.Push("StackNonGeneric2");

        FieldPublicIEnumerable = FieldPublicSortedList;

        FieldPublicBlockingCollection = new System.Collections.Concurrent.BlockingCollection <string>();
        FieldPublicBlockingCollection.Add("BlockingCollection1");
        FieldPublicBlockingCollection.Add("BlockingCollection2");

        FieldPublicConcurrentBag = new System.Collections.Concurrent.ConcurrentBag <string>();
        FieldPublicConcurrentBag.Add("ConcurrentBag1");
        FieldPublicConcurrentBag.Add("ConcurrentBag2");
        FieldPublicConcurrentBag.Add("ConcurrentBag3");

        FieldPublicConcurrentDictionary = new System.Collections.Concurrent.ConcurrentDictionary <string, int>();
        FieldPublicConcurrentDictionary.GetOrAdd("ConcurrentDictionary1", 0);
        FieldPublicConcurrentDictionary.GetOrAdd("ConcurrentDictionary2", 0);

        FieldPublicConcurrentQueue = new System.Collections.Concurrent.ConcurrentQueue <string>();
        FieldPublicConcurrentQueue.Enqueue("ConcurrentQueue1");
        FieldPublicConcurrentQueue.Enqueue("ConcurrentQueue2");

        FieldPublicConcurrentStack = new System.Collections.Concurrent.ConcurrentStack <string>();
        FieldPublicConcurrentStack.Push("ConcurrentStack1");
        FieldPublicConcurrentStack.Push("ConcurrentStack2");

        // FieldPublicOrderablePartitioner = new OrderablePartitioner();
        // FieldPublicPartitioner;
        // FieldPublicPartitionerNonGeneric;

        FieldPublicHybridDictionary = new System.Collections.Specialized.HybridDictionary();
        FieldPublicHybridDictionary.Add("HybridDictionaryKey1", "HybridDictionary1");
        FieldPublicHybridDictionary.Add("HybridDictionaryKey2", "HybridDictionary2");

        FieldPublicListDictionary = new System.Collections.Specialized.ListDictionary();
        FieldPublicListDictionary.Add("ListDictionaryKey1", "ListDictionary1");
        FieldPublicListDictionary.Add("ListDictionaryKey2", "ListDictionary2");
        FieldPublicNameValueCollection = new System.Collections.Specialized.NameValueCollection();
        FieldPublicNameValueCollection.Add("Key1", "Value1");
        FieldPublicNameValueCollection.Add("Key2", "Value2");

        FieldPublicOrderedDictionary = new System.Collections.Specialized.OrderedDictionary();
        FieldPublicOrderedDictionary.Add(1, "OrderedDictionary1");
        FieldPublicOrderedDictionary.Add(2, "OrderedDictionary1");
        FieldPublicOrderedDictionary.Add("OrderedDictionaryKey2", "OrderedDictionary2");

        FieldPublicStringCollection = new System.Collections.Specialized.StringCollection();
        FieldPublicStringCollection.Add("StringCollection1");
        FieldPublicStringCollection.Add("StringCollection2");

        #endregion

        #region Several

        PropXmlDocument = new XmlDocument();
        PropXmlDocument.LoadXml("<xml>something</xml>");

        var tr = new StringReader("<Root>Content</Root>");
        PropXDocument         = XDocument.Load(tr);
        PropStream            = GenerateStreamFromString("Stream");
        PropBigInteger        = new System.Numerics.BigInteger(100);
        PropStringBuilder     = new StringBuilder("StringBuilder");
        FieldPublicIQueryable = new List <string>()
        {
            "IQueryable"
        }.AsQueryable();

        #endregion

        #region Custom

        FieldPublicMyCollectionPublicGetEnumerator           = new MyCollectionPublicGetEnumerator("a b c", new char[] { ' ' });
        FieldPublicMyCollectionInheritsPublicGetEnumerator   = new MyCollectionInheritsPublicGetEnumerator("a b c", new char[] { ' ' });
        FieldPublicMyCollectionExplicitGetEnumerator         = new MyCollectionExplicitGetEnumerator("a b c", new char[] { ' ' });
        FieldPublicMyCollectionInheritsExplicitGetEnumerator = new MyCollectionInheritsExplicitGetEnumerator("a b c", new char[] { ' ' });
        FieldPublicMyCollectionInheritsTooIEnumerable        = new MyCollectionInheritsTooIEnumerable("a b c", new char[] { ' ' });

        FieldPublicEnumSpecific = EnumTest.ValueB;
        MyDelegate            = MethodDelegate;
        EmptyClass            = new EmptyClass();
        StructGeneric         = new ThreeTuple <int>(0, 1, 2);
        StructGenericNullable = new ThreeTuple <int>(0, 1, 2);
        FieldPublicNullable   = new Nullable <ThreeTuple <int> >(StructGeneric);

        #endregion
    }
 public LinkedListNode <T> AddAfter(LinkedListNode <T> node, T value) => linkedList.AddAfter(node, value);
Example #7
0
        static void Main(string[] args)
        {
            IncreaseCost[] applications = new IncreaseCost[4];
            IncreaseCost   app0         = new Game("Heroes3", 15, 200, "No license");
            IncreaseCost   app1         = new Game("Disciples", 5, 500, "Official license");
            IncreaseCost   app2         = new Software("Util_1", 0, 30);
            IncreaseCost   app3         = new Software("Util_1", 0, 40);

            applications[0] = app0;
            applications[1] = app1;
            applications[2] = app2;
            applications[3] = app3;

            list1.AddRange(applications);

            list2.AddFirst(app0);
            list2.AddAfter(list2.First, app1);
            list2.AddLast(app2);
            list2.AddAfter(list2.Last, app3);

            //list1.Add(new Game("Heroes3", 15, 200, "No license"));

            int flag = 100;

            while (flag != 0)
            {
                Console.Clear();
                Console.WriteLine("Меню : ");
                Console.WriteLine("1 – просмотр коллекции");
                Console.WriteLine("2 – добавление элемента (используйте конструктор с 1-2 параметрами)");
                Console.WriteLine("3 – добавление элемента по указанному индексу");
                Console.WriteLine("4 – нахождение элемента с начала коллекции (переопределить метод Equals или оператор == для вашего класса – сравнение только по полю name)");
                Console.WriteLine("5 – нахождение элемента с конца коллекции");
                Console.WriteLine("6 – удаление элемента по индексу");
                Console.WriteLine("7 – удаление элемента по значению");
                Console.WriteLine("8 – реверс коллекции");
                Console.WriteLine("9 – сортировка");
                Console.WriteLine("10 – выполнение методов всех объектов, поддерживающих Interface2");

                Console.WriteLine("11 – LinkedList просмотр коллекции");
                Console.WriteLine("12 – LinkedList добавление элемента (используйте конструктор с 1-2 параметрами)");
                Console.WriteLine("13 – LinkedList добавление элемента по указанному индексу");
                Console.WriteLine("14 – LinkedList нахождение элемента с начала коллекции (переопределить метод Equals или оператор == для вашего класса – сравнение только по полю name)");
                Console.WriteLine("15 – LinkedList нахождение элемента с конца коллекции");
                Console.WriteLine("16 – LinkedList удаление элемента по индексу");
                Console.WriteLine("17 – LinkedList удаление элемента по значению");
                Console.WriteLine("18 – LinkedList реверс коллекции");
                Console.WriteLine("19 – LinkedList сортировка");
                Console.WriteLine("20 – LinkedList выполнение методов всех объектов, поддерживающих Interface2");

                Console.WriteLine("0 – выход");
                flag = Convert.ToInt32(Console.ReadLine());

                switch (flag)
                {
                //просмотр коллекции
                case (1):
                {
                    Console.Clear();

                    if (Program.list1.Count > 0)
                    {
                        Console.WriteLine("list1 содержит : " + list1.Count);
                        foreach (Object obj in Program.list1)
                        {
                            Console.WriteLine("************************************************************");
                            Console.WriteLine(obj.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("list1 пустой");
                    }

                    Console.ReadLine();
                    break;
                }

                //добавление элемента
                case (2):
                {
                    Console.Clear();

                    Console.WriteLine("Теперь создаем обьект");
                    Console.WriteLine("Введите name");
                    String name = Console.ReadLine();
                    Console.WriteLine("Введите bugs");
                    int bugs = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Введите cost");
                    double cost = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("Введите licenseAgreement");
                    String licenseAgreement = Console.ReadLine();

                    if (licenseAgreement.Equals("0"))
                    {
                        list1.Add(new Software(name, bugs, cost));
                        Console.WriteLine("Done");
                        Console.WriteLine("создали Software");
                    }
                    else
                    {
                        list1.Add(new Game(name, bugs, cost, licenseAgreement));
                        Console.WriteLine("Done");
                        Console.WriteLine("создали Game");
                    }
                    Console.WriteLine("И добавили в list1");

                    Console.ReadLine();
                    break;
                }

                //добавление элемента по указанному индексу
                case (3):
                {
                    Console.Clear();
                    try
                    {
                        Console.WriteLine("Теперь создаем обьект");
                        Console.WriteLine("Введите name");
                        String name = Console.ReadLine();
                        Console.WriteLine("Введите bugs");
                        int bugs = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Введите cost");
                        double cost = Convert.ToDouble(Console.ReadLine());
                        Console.WriteLine("Введите licenseAgreement");
                        String licenseAgreement = Console.ReadLine();
                        Console.WriteLine("Введите index");
                        int index = Convert.ToInt32(Console.ReadLine());

                        if (licenseAgreement.Equals("0"))
                        {
                            list1.Insert(index, new Software(name, bugs, cost));
                            Console.WriteLine("Done");
                            Console.WriteLine("создали Software");
                        }
                        else
                        {
                            list1.Insert(index, new Game(name, bugs, cost, licenseAgreement));
                            Console.WriteLine("Done");
                            Console.WriteLine("создали Game");
                        }
                        Console.WriteLine("И добавили в list1");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Не могу выполнить");
                    }

                    Console.ReadLine();
                    break;
                }

                //нахождение элемента с начала коллекции
                case (4):
                {
                    Console.Clear();

                    Console.WriteLine("Находим элемент по имени name с начала");
                    Console.WriteLine("Введите name");
                    String   name    = Console.ReadLine();
                    Software finding = null;
                    for (int i = 0; i < list1.Count; i++)
                    {
                        if (name.Equals(((Software)list1[i]).getName()))
                        {
                            finding = (Software)list1[i];
                            break;
                        }
                    }

                    if (finding != null)
                    {
                        Console.WriteLine("Нашел");
                        if (finding is Game)
                        {
                            Console.WriteLine(((Game)finding).ToString());
                        }
                        else
                        {
                            Console.WriteLine(((Software)finding).ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Не нашел");
                    }

                    Console.ReadLine();
                    break;
                }

                //нахождение элемента с конца коллекции
                case (5):
                {
                    Console.Clear();

                    Console.WriteLine("Находим элемент по имени name с конца");
                    Console.WriteLine("Введите name");
                    String   name    = Console.ReadLine();
                    Software finding = null;

                    for (int i = list1.Count - 1; i >= 0; i--)
                    {
                        if (name.Equals(((Software)list1[i]).getName()))
                        {
                            finding = (Software)list1[i];
                            break;
                        }
                    }

                    if (finding != null)
                    {
                        Console.WriteLine("Нашел");
                        if (finding is Game)
                        {
                            Console.WriteLine(((Game)finding).ToString());
                        }
                        else
                        {
                            Console.WriteLine(((Software)finding).ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Не нашел");
                    }

                    Console.ReadLine();
                    break;
                }

                //удаление элемента по индексу
                case (6):
                {
                    Console.Clear();

                    try
                    {
                        Console.WriteLine("Удалим элемент по индексу");
                        Console.WriteLine("Введите индекс");
                        int index = Convert.ToInt32(Console.ReadLine());
                        list1.RemoveAt(index);
                        Console.WriteLine("Эх жаль элемента");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Че-то пошло не так :)");
                    }

                    Console.ReadLine();
                    break;
                }

                //удаление элемента по значению
                case (7):
                {
                    Console.Clear();

                    try
                    {
                        Console.WriteLine("Удалим элемент по значению");
                        Console.WriteLine("Введите name");
                        String name = Console.ReadLine();
                        for (int i = 0; i < list1.Count; i++)
                        {
                            if (name.Equals(((Software)list1[i]).getName()))
                            {
                                list1.RemoveAt(i);
                                Console.WriteLine("Эх жаль элемента");
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Че-то пошло не так :)");
                    }

                    Console.ReadLine();
                    break;
                }

                //реверс коллекции
                case (8):
                {
                    Console.Clear();

                    Console.WriteLine("Произведем реверс list1");
                    list1.Reverse();
                    Console.WriteLine("Готово :)");

                    Console.ReadLine();
                    break;
                }

                //сортировка
                case (9):
                {
                    Console.Clear();

                    Console.WriteLine("Отсортируем по name list1");
                    list1.Sort();
                    Console.WriteLine("Готово )");

                    Console.ReadLine();
                    break;
                }

                //выполнение методов всех объектов, поддерживающих Interface2
                case (10):
                {
                    Console.Clear();

                    foreach (IncreaseCost obj in list1)
                    {
                        if (obj is DecreaseCost)
                        {
                            Console.WriteLine("Ура");
                            Console.WriteLine("************************************************************");
                            ((DecreaseCost)obj).decreaseCost();
                            ((DecreaseCost)obj).information();
                            ((DecreaseCost)obj).statistic();
                            ((DecreaseCost)obj).info();
                        }
                    }


                    Console.ReadLine();
                    break;
                }


                //LinkedList просмотр коллекции
                case (11):
                {
                    Console.Clear();

                    if (Program.list2.Count > 0)
                    {
                        Console.WriteLine("list2 содержит : " + list2.Count);
                        foreach (Object obj in Program.list2)
                        {
                            Console.WriteLine("************************************************************");
                            Console.WriteLine(obj.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("list2 пустой");
                    }

                    Console.ReadLine();
                    break;
                }

                //LinkedList добавление элемента
                case (12):
                {
                    Console.Clear();

                    Console.WriteLine("Теперь создаем обьект");
                    Console.WriteLine("Введите name");
                    String name = Console.ReadLine();
                    Console.WriteLine("Введите bugs");
                    int bugs = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Введите cost");
                    double cost = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("Введите licenseAgreement");
                    String licenseAgreement = Console.ReadLine();

                    if (licenseAgreement.Equals("0"))
                    {
                        list2.AddFirst(new Software(name, bugs, cost));
                        Console.WriteLine("Done");
                        Console.WriteLine("создали Software");
                    }
                    else
                    {
                        list2.AddFirst(new Game(name, bugs, cost, licenseAgreement));
                        Console.WriteLine("Done");
                        Console.WriteLine("создали Game");
                    }
                    Console.WriteLine("И добавили в list2");

                    Console.ReadLine();
                    break;
                }

                //LinkedList добавление элемента по указанному индексу
                case (13):
                {
                    Console.Clear();
                    try
                    {
                        Console.WriteLine("Теперь создаем обьект");
                        Console.WriteLine("Введите name");
                        String name = Console.ReadLine();
                        Console.WriteLine("Введите bugs");
                        int bugs = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Введите cost");
                        double cost = Convert.ToDouble(Console.ReadLine());
                        Console.WriteLine("Введите licenseAgreement");
                        String licenseAgreement = Console.ReadLine();
                        Console.WriteLine("Введите index обьекта после котрого вставим этот");
                        int          index = Convert.ToInt32(Console.ReadLine());
                        IncreaseCost obj   = list2.ElementAt(index);


                        if (licenseAgreement.Equals("0"))
                        {
                            list2.AddAfter(list2.Find(obj), new Software(name, bugs, cost));
                            Console.WriteLine("Done");
                            Console.WriteLine("создали Software");
                        }
                        else
                        {
                            list2.AddAfter(list2.Find(obj), new Game(name, bugs, cost, licenseAgreement));
                            Console.WriteLine("Done");
                            Console.WriteLine("создали Game");
                        }
                        Console.WriteLine("И добавили в list2");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Не могу выполнить");
                    }

                    Console.ReadLine();
                    break;
                }

                //LinkedList нахождение элемента с начала коллекции
                case (14):
                {
                    Console.Clear();

                    Console.WriteLine("Находим элемент по имени name с начала");
                    Console.WriteLine("Введите name");
                    String   name    = Console.ReadLine();
                    Software finding = null;

                    LinkedListNode <IncreaseCost> node = list2.First;
                    for (int i = 0; i < list2.Count; i++)
                    {
                        IncreaseCost obj = node.Value;
                        if (name.Equals(((Software)obj).getName()))
                        {
                            finding = (Software)obj;
                        }
                        node = node.Next;
                    }

                    if (finding != null)
                    {
                        Console.WriteLine("Нашел");
                        if (finding is Game)
                        {
                            Console.WriteLine(((Game)finding).ToString());
                        }
                        else
                        {
                            Console.WriteLine(((Software)finding).ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Не нашел");
                    }

                    Console.ReadLine();
                    break;
                }

                //LinkedList нахождение элемента с конца коллекции
                case (15):
                {
                    Console.Clear();

                    Console.WriteLine("Находим элемент по имени name с начала");
                    Console.WriteLine("Введите name");
                    String   name    = Console.ReadLine();
                    Software finding = null;

                    LinkedListNode <IncreaseCost> node = list2.Last;
                    for (int i = 0; i < list2.Count; i++)
                    {
                        IncreaseCost obj = node.Value;
                        if (name.Equals(((Software)obj).getName()))
                        {
                            finding = (Software)obj;
                        }
                        node = node.Previous;
                    }

                    if (finding != null)
                    {
                        Console.WriteLine("Нашел");
                        if (finding is Game)
                        {
                            Console.WriteLine(((Game)finding).ToString());
                        }
                        else
                        {
                            Console.WriteLine(((Software)finding).ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Не нашел");
                    }

                    Console.ReadLine();
                    break;
                }

                //LinkedList удаление элемента по индексу
                case (16):
                {
                    Console.Clear();

                    try
                    {
                        Console.WriteLine("Удалим элемент по индексу");
                        Console.WriteLine("Введите индекс");
                        int index = Convert.ToInt32(Console.ReadLine());
                        list2.Remove(list2.ElementAt(index));
                        Console.WriteLine("Эх жаль элемента");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Че-то пошло не так :)");
                    }

                    Console.ReadLine();
                    break;
                }

                //LinkedList удаление элемента по значению
                case (17):
                {
                    Console.Clear();

                    try
                    {
                        Console.WriteLine("Удалим элемент по значению");
                        Console.WriteLine("Введите name");
                        String name = Console.ReadLine();
                        LinkedListNode <IncreaseCost> node = list2.First;
                        for (int i = 0; i < list2.Count; i++)
                        {
                            IncreaseCost obj = node.Value;
                            if (name.Equals(((Software)obj).getName()))
                            {
                                list2.Remove(obj);
                                Console.WriteLine("Эх жаль элемента");
                                break;
                            }
                            node = node.Next;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Че-то пошло не так :)");
                    }

                    Console.ReadLine();
                    break;
                }

                //LinkedList реверс коллекции
                case (18):
                {
                    Console.Clear();

                    Console.WriteLine("Произведем реверс list2");
                    IncreaseCost[]            array = list2.ToArray();
                    LinkedList <IncreaseCost> list3 = new LinkedList <IncreaseCost>();
                    foreach (IncreaseCost obj in list2)
                    {
                        list3.AddFirst(obj);
                    }
                    list2 = list3;
                    Console.WriteLine("Готово :)");

                    Console.ReadLine();
                    break;
                }

                //LinkedList сортировка
                case (19):
                {
                    Console.Clear();

                    Console.WriteLine("Отсортируем по name list2");
                    IncreaseCost[] array = new IncreaseCost[list2.Count];
                    int            i     = 0;
                    foreach (IncreaseCost obj in list2)
                    {
                        array[i] = obj;
                        i++;
                    }
                    Array.Sort(array);
                    list2.Clear();
                    for (int q = 0; q < array.Length; q++)
                    {
                        list2.AddLast(array[q]);
                    }
                    Console.WriteLine("Готово )");

                    Console.ReadLine();
                    break;
                }

                //выполнение методов всех объектов, поддерживающих Interface2
                case (20):
                {
                    Console.Clear();

                    foreach (IncreaseCost obj in list2)
                    {
                        if (obj is DecreaseCost)
                        {
                            Console.WriteLine("Ура");
                            Console.WriteLine("************************************************************");
                            ((DecreaseCost)obj).decreaseCost();
                            ((DecreaseCost)obj).information();
                            ((DecreaseCost)obj).statistic();
                            ((DecreaseCost)obj).info();
                        }
                    }

                    Console.ReadLine();
                    break;
                }



                case (0):
                {
                    Console.Clear();
                    break;
                }
                }
            }
        }
        static void Main(string[] args)
        {
            // this is the default doubleLinkedList
            var lc = new  System.Collections.Generic.LinkedList <int>();

            // adding data

            for (int i = 0; i <= 10; i++)
            {
                lc.AddLast(i);
            }

            var data = lc.First.Next.Next;


            lc.AddAfter(data, 100);
            foreach (var i in lc)
            {
                Console.WriteLine(i);
            }

            // because this LinkedList is  double link List
            // we can add before too
            lc.AddBefore(data, 100);
            foreach (var i in lc)
            {
                Console.WriteLine(i);
            }

            // this will return a bool

            Console.WriteLine(lc.Contains(100));


            LinkedList <String> my_list = new LinkedList <String>();

            // Adding elements in the LinkedList
            // Using AddLast() method
            my_list.AddLast("Zoya");
            my_list.AddLast("Shilpa");
            my_list.AddLast("Rohit");
            my_list.AddLast("Rohan");
            my_list.AddLast("Juhi");
            my_list.AddLast("Zoya");

            // Inital number of elements
            Console.WriteLine("Best students of XYZ " +
                              "university initially:");

            // Accessing the elements of
            // Linkedlist Using foreach loop
            foreach (string str in my_list)
            {
                Console.WriteLine(str);
            }

            // After using Remove(LinkedListNode)
            // method
            Console.WriteLine("Best students of XYZ" +
                              " university in 2000:");

            my_list.Remove(my_list.First);

            foreach (string str in my_list)
            {
                Console.WriteLine(str);
            }

            // After using Remove(T) method
            Console.WriteLine("Best students of XYZ" +
                              " university in 2001:");

            my_list.Remove("Rohit");

            foreach (string str in my_list)
            {
                Console.WriteLine(str);
            }

            // After using RemoveFirst() method
            Console.WriteLine("Best students of XYZ" +
                              " university in 2002:");

            my_list.RemoveFirst();

            foreach (string str in my_list)
            {
                Console.WriteLine(str);
            }

            // After using RemoveLast() method
            Console.WriteLine("Best students of XYZ" +
                              " university in 2003:");

            my_list.RemoveLast();

            foreach (string str in my_list)
            {
                Console.WriteLine(str);
            }

            // After using Clear() method
            my_list.Clear();
            Console.WriteLine("Number of students: {0}",
                              my_list.Count);
        }