Пример #1
0
        private static Cup Initialize(IEnumerable <int> values, Dictionary <int, Cup> cache)
        {
            Cup head = null;
            Cup prev = null;

            foreach (int value in values)
            {
                var current = new Cup(value);

                if (head == null)
                {
                    head = current;
                }

                if (prev != null)
                {
                    current.AttachAfter(prev);
                }

                prev = current;

                if (cache != null)
                {
                    cache.Add(value, current);
                }
            }

            if (prev != null)
            {
                head.AttachAfter(prev);
            }

            return(head);
        }