Exemplo n.º 1
0
        public CircularItem <T> AddItemAfter(CircularItem <T> circItem, T value)
        {
            if (circItem == null)
            {
                return(AddItem(value));
            }

            CircularItem <T> item;

            if (_removed != null)
            {
                item       = _removed;
                item.Value = value;
                _removed   = _removed.Next;
            }
            else
            {
                item = new CircularItem <T>(value);
            }

            item.Next              = circItem.Next;
            item.Previous          = circItem;
            circItem.Next.Previous = item;
            circItem.Next          = item;

            Last = item;
            return(Last);
        }
Exemplo n.º 2
0
        public CircularItem <T> AddItem(T value)
        {
            CircularItem <T> item;

            if (_removed != null)
            {
                item       = _removed;
                item.Value = value;
                _removed   = _removed.Next;
            }
            else
            {
                item = new CircularItem <T>(value);
            }

            if (Last != null)
            {
                item.Next          = Last.Next;
                item.Previous      = Last;
                Last.Next.Previous = item;
                Last.Next          = item;
            }
            else
            {
                item.Next     = item;
                item.Previous = item;
            }

            Last = item;
            return(Last);
        }
Exemplo n.º 3
0
        public void LinkTwoItem(CircularItem <T> left, CircularItem <T> right)
        {
            if (left.Next != right)
            {
                // есть кого удалять в кольце
                right.Previous.Next = _removed;
                _removed            = left.Next;
                _removed.Previous   = null;
            }

            left.Next      = right;
            right.Previous = left;
            Last           = right;
        }
Exemplo n.º 4
0
        public CircularItem <T> FindPrevious(CircularItem <T> from, Predicate <CircularItem <T> > match)
        {
            var result = from.Previous;

            while (result != from)
            {
                if (match(result))
                {
                    return(result);
                }
                result = result.Previous;
            }

            return(null);
        }
Exemplo n.º 5
0
        public CircularItem <T> FindNext(CircularItem <T> from, Predicate <CircularItem <T> > match)
        {
            var result = from.Next;

            while (result != from)
            {
                if (match(result))
                {
                    return(result);
                }
                result = result.Next;
            }

            return(null);
        }
Exemplo n.º 6
0
 public CircularList()
 {
     Last     = null;
     _removed = null;
 }