Ejemplo n.º 1
0
        public void Push(object current)
        {
            Node temp = new Node();

            temp.SetData(current);
            temp.SetNext(top);
            top = temp;
        }
        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();
        }
        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)
        {
            Node <T> node = new Node <T>(item);

            if (_size == 0)
            {
                _first = node;
            }
            else
            {
                node.SetNext(_first);
                _first.SetPrevious(node);
                _first = node;
            }
            _size++;
            OnAddElement(new DataStructEventArgs <T>(item));
        }
Ejemplo n.º 5
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());
        }