Пример #1
0
        public static void Demo()
        {
            var mylist = new MyLinkedList <object>();

            mylist.PrintList();
            mylist.AddFirst(1);
            mylist.AddFirst(2);
            mylist.AddFirst(3);
            mylist.AddLast(4);
            mylist.AddLast(6);
            mylist.AddLast("Basant");
            mylist.AddFirst("abc");
            mylist.PrintList();

            Console.WriteLine("printing for each");
            foreach (var item in mylist)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("for each completed..");

            var arr = new object[10];

            mylist.CopyTo(arr, arr.Length);

            Console.WriteLine(arr[6]);
            mylist.Remove("Basant");
            mylist.PrintList();
            while (mylist.Count > 0)
            {
                mylist.RemoveLast();
                mylist.PrintList();
            }
        }
Пример #2
0
        public T Pop()
        {
            if (_stack.Count > 0)
            {
                T item = _stack.Tail.Value;

                _stack.RemoveLast();
                return(item);
            }
            else
            {
                throw new InvalidOperationException();
            }
        }