Ejemplo n.º 1
0
        public SimpleListItem <T> GetItem(int number)
        {
            if ((number < 0) || (number >= this.Count))
            {
                throw new Exception("Выход за границу индекса");
            }

            SimpleListItem <T> current = this.first;
            int i = 0;

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

            return(current);
        }
Ejemplo n.º 2
0
        public void Add(T element)
        {
            SimpleListItem <T> newItem = new SimpleListItem <T>(element);

            this.Count++;

            if (last == null)
            {
                this.first = newItem;
                this.last  = newItem;
            }

            else
            {
                this.last.next = newItem;
                this.last      = newItem;
            }
        }
Ejemplo n.º 3
0
        public T Pop()
        {
            T Result = default(T);

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