public void Expand(int length)
        {
            Node <T> currentNode = _end;
            Node <T> lastNode    = _end.GetNext();

            for (int i = 0; i < length; i++)
            {
                currentNode.SetNext(new Node <T>());
                currentNode.GetNext().SetPrevious(currentNode);
                currentNode.GetNext().SetNext(lastNode);
                currentNode = currentNode.GetNext();
            }
            _size += length;
        }
 public override void Add(T item)
 {
     if (_count < _size)
     {
         _end = _end.GetNext();
         _end.SetItem(item);
         _count++;
         OnAddElement(new DataStructEventArgs <T>(item));
     }
     else
     {
         OnContainerFull(new DataStructEventArgs <T>(item));
         throw new DataStructureIsFullOnInsertExeption("RingBufferLinkedList");
     }
 }
 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();
         }
     }
 }
        public object Dequeue()
        {
            if (first == null)
            {
                throw new EmptyQueueException("The Queue is empty");
            }
            Node temp = first;

            first = first.GetNext();
            size--;
            return(temp.GetData());
        }
 public bool MoveNext()
 {
     if (_position == null)
     {
         _position = _first;
     }
     else
     {
         _position = _position.GetNext();
     }
     return(_position != null);
 }
        public RingBufferLinkedList(int length)
        {
            if (length < 1)
            {
                throw new ArgumentException();
            }
            _first = new Node <T>();

            Node <T> currentNode = _first;

            for (int i = 0; i < length - 1; i++)
            {
                currentNode.SetNext(new Node <T>());
                currentNode.GetNext().SetPrevious(currentNode);
                currentNode = currentNode.GetNext();
            }
            currentNode.SetNext(_first);
            _first.SetPrevious(currentNode);
            _size = length;
            _end  = _first.GetPrevious();
        }
Example #7
0
 public bool MoveNext()
 {
     _current++;
     if (_position == null)
     {
         _position = _first;
     }
     else
     {
         _position = _position.GetNext();
     }
     return(_current != _size);
 }
        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);
        }
Example #9
0
        public object Pop()
        {
            object currentTop;

            if (IsEmpty())
            {
                throw new EmptyStackException("The Stack is empty");
            }
            else
            {
                currentTop = top.GetData();
                top        = top.GetNext();
            }
            return(currentTop);
        }
        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);
        }
        public T GetFirst()
        {
            if (_size == 0)
            {
                throw new DataStructureIsEmptyOnReadExeption("Linked List");
            }
            Node <T> result = _first;

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