Esempio n. 1
0
        public void RemoveAt(int index)
        {
            if (IsEmpty())
            {
                throw new NullReferenceException();
            }

            var             cur = _header;
            SlinkedNode <T> pre = null;

            for (int i = 0; i < index && cur != null; i++)
            {
                pre = cur;
                cur = cur.Next;
            }
            if (pre == null)
            {
                _header = cur.Next;
            }
            else
            {
                pre.Next = cur.Next;
                if (index == _size - 1)
                {
                    _trailer = pre;
                }
            }
            cur = null;
            _size--;
        }
Esempio n. 2
0
        public void Insert(int index, T item)
        {
            if (index < 0 || index >= _size)
            {
                throw new IndexOutOfRangeException();
            }
            if (index == 0)
            {
                PushFont(item);
                return;
            }
            var             curr = _header;
            SlinkedNode <T> pre  = null;

            for (int i = 0; i < index && curr != null; i++)
            {
                pre  = curr;
                curr = curr.Next;
            }

            SlinkedNode <T> node = new SlinkedNode <T>(item);

            node.Next = curr;
            pre.Next  = node;
            _size++;
        }
Esempio n. 3
0
        public void PushFont(T item)
        {
            SlinkedNode <T> node = new SlinkedNode <T>(item);

            if (_size == 0)
            {
                _header  = node;
                _trailer = node;
            }
            else
            {
                node.Next = _header;
                _header   = node;
            }
            _size++;
        }
Esempio n. 4
0
        public void PushBack(T item)
        {
            SlinkedNode <T> node = new SlinkedNode <T>(item);

            if (_size == 0)
            {
                _header  = node;
                _trailer = node;
            }
            else
            {
                _trailer.Next = node;
                _trailer      = node;
            }
            _size++;
        }
Esempio n. 5
0
 public SLinkedList()
 {
     _size   = 0;
     _header = _trailer = null;
 }