示例#1
0
 public T Pop()
 {
     SimpleList.SimpleListItem <T> itemPopped = last;
     Count = Count - 1;
     if (Count == 0)
     {
         last  = null;
         first = null;
     }
     else
     {
         SimpleList.SimpleListItem <T> newLastItem = this.GetItem(Count - 1);
         newLastItem.next = null;
         last             = newLastItem;
     }
     return(itemPopped.data);
 }
示例#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;
            }
        }
示例#3
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);
        }