public override T this[int index]
 {
     get
     {
         if (index >= 0 && index < _size)
         {
             Node <T> result = _first;
             for (int i = 0; i < index; i++)
             {
                 result = result.GetNext();
             }
             return(result.GetItem());
         }
         throw new IndexOutOfRangeException();
     }
     set
     {
         if (index >= 0 && index < _size)
         {
             Node <T> result = _first;
             for (int i = 0; i < index; i++)
             {
                 result = result.GetNext();
             }
             result.SetItem(value);
         }
         else
         {
             throw new IndexOutOfRangeException();
         }
     }
 }
예제 #2
0
        public override T Get()
        {
            if (_size == 0)
            {
                throw new DataStructureIsEmptyOnReadExeption("Linked List");
            }
            Node <T> result = _last;

            _last = _last.GetPrevious();
            if (_size == 1)
            {
                Clear();
            }
            else
            {
                _last.SetNext(null);
                _size--;
            }
            OnRemoveElement(new DataStructEventArgs <T>(result.GetItem()));
            return(result.GetItem());
        }
        public override T Get()
        {
            if (_count == 0)
            {
                throw new DataStructureIsEmptyOnReadExeption("RingBufferLinkedList");
            }
            T result = _first.GetItem();

            _first = _first.GetNext();
            _count--;
            OnRemoveElement(new DataStructEventArgs <T>(result));
            return(result);
        }
예제 #4
0
        public override void Add(T item)
        {
            Node <T> node = new Node <T>(item);

            if (_size == 0)
            {
                _first = node;
                _last  = node;
            }
            else
            {
                _last.SetNext(node);
                node.SetPrevious(_last);
                _last = node;
            }
            _size++;
            OnAddElement(new DataStructEventArgs <T>(node.GetItem()));
        }
        public override T Get()
        {
            if (_size == 0)
            {
                throw new DataStructureIsEmptyOnReadExeption("StackLinkedList");
            }
            T result = _first.GetItem();

            if (_size == 1)
            {
                Clear();
            }
            else
            {
                _first = _first.GetNext();
                _size--;
            }
            OnRemoveElement(new DataStructEventArgs <T>(result));
            return(result);
        }