Example #1
0
        public SimpleListItem <T> GetItem(int number)
        {
            if ((number < 0) || (number >= Count))
            {
                throw new Exception("Выход за границу индекса");
            }
            SimpleListItem <T> current = first;
            int i = 0;

            while (i < number)
            {
                current = current.next;
                i++;
            }

            return(current);
        }
Example #2
0
        public void Add(T element)
        {
            var newItem = new SimpleListItem <T>(element);

            this.Count++;

            if (last == null)
            {
                first = newItem;
                last  = newItem;
            }
            else
            {
                last.next = newItem;
                last      = newItem;
            }
        }
Example #3
0
        public T Pop()
        {
            T current = default(T);

            if (Count == 0)
            {
                return(current);
            }
            if (Count == 1)
            {
                current = first.data;
                first   = null;
                last    = null;
            }
            else
            {
                SimpleListItem <T> newLast = GetItem(Count - 2);
                current      = newLast.next.data;
                last         = newLast;
                newLast.next = null;
            }
            Count--;
            return(current);
        }