Пример #1
0
        public Cons <T> Remove(T item)
        {
            Stack <T> acc  = new Stack <T>();
            Cons <T>  curr = this;

            while (!curr.IsEmpty)
            {
                if (EqualityComparer <T> .Default.Equals(curr.Head, item))
                {
                    while (acc.Count != 0)
                    {
                        curr = new Cons <T>(curr.Tail.Length + 1, acc.Pop(), curr.Tail);
                    }
                    return(curr);
                }

                acc.Push(curr.Head);
                curr = curr.Tail;
            }
            return(this);
        }
Пример #2
0
 private Cons(int length, T head, Cons <T> tail)
 {
     Length = length;
     Head   = head;
     Tail   = tail;
 }