Пример #1
0
            public T GetNext()
            {
                LLItem item = this.current;

                this.current = item.Next;

                return(item.Value);
            }
Пример #2
0
        private LLItem GetItem(int index)
        {
            LLItem x = this.first;

            for (int i = 0; i < index; i++)
            {
                x = x.Next;
            }

            return(x);
        }
Пример #3
0
        // Enumerator (yield)
        public IEnumerator <T> GetEnumerator()
        {
            LLItem item = this.first;

            while (item != null)
            {
                yield return(item.Value);

                item = item.Next;
            }
        }
Пример #4
0
        public void Add(T value)
        {
            LLItem i = new LLItem()
            {
                Value = value
            };

            if (this.first == null)
            {
                this.first = i;
            }
            else
            {
                this.last.Next = i;
            }

            this.last = i;
        }
Пример #5
0
        public void RemoveAt(int index)
        {
            if (index == 0)
            {
                this.first = this.first.Next;

                if (this.first == null)
                {
                    this.last = null;
                }
            }
            else
            {
                LLItem x = this.GetItem(index - 1);
                x.Next = x.Next.Next;

                if (x.Next == null)
                {
                    this.last = x;
                }
            }
        }
Пример #6
0
        public void Insert(int index, T value)
        {
            LLItem n = new LLItem()
            {
                Value = value
            };

            if (index > 0)
            {
                LLItem x = this.GetItem(index - 1);
                n.Next = x.Next;
                x.Next = n;

                if (n.Next == null)
                {
                    this.last = n;
                }
            }
            else
            {
                n.Next     = this.first;
                this.first = n;
            }
        }
Пример #7
0
 public void Clear()
 {
     this.first = this.last = null;
 }
Пример #8
0
 public LLIterator(LLItem item)
 {
     this.current = item;
 }