Example #1
0
        protected override Cup Extends(Cup cup, int max)
        {
            var tmpCup = cup;

            for (var i = max + 1; i <= 1000000; ++i)
            {
                var newCup = new Cup(i);
                tmpCup.SetNext(newCup);
                tmpCup = newCup;
            }
            return(tmpCup);
        }
        public List <Cup> GetAll(Cup start)
        {
            var result = new List <Cup>();
            var cup    = start;

            do
            {
                result.Add(cup);
                cup = cup.Next;
            } while (cup.Id != start.Id);

            return(result);
        }
        public Circle(Cup start)
        {
            Start  = start;
            Memory = new Dictionary <int, Cup>();
            var cup = start;

            MaxId = cup.Id;
            do
            {
                Memory.Add(cup.Id, cup);
                cup = cup.Next;
                if (MaxId < cup.Id)
                {
                    MaxId = cup.Id;
                }
            } while (cup.Id != start.Id);
        }
Example #4
0
        private int GetInsertCupId(Circle circle, Cup cup, List <Cup> list)
        {
            var search = cup.Id - 1;

            if (search == 0)
            {
                search = circle.MaxId;
            }
            while (list.Where(x => x.Id == search).Any())
            {
                search--;
                if (search == 0)
                {
                    search = circle.MaxId;
                }
            }

            return(search);
        }
Example #5
0
        private Circle CreateCircle(List <string> input)
        {
            var max   = int.Parse(input[0][0].ToString());
            var start = new Cup(max);
            var cup   = start;

            foreach (var c in input[0].Skip(1))
            {
                var id = int.Parse(c.ToString());
                if (id > max)
                {
                    max = id;
                }
                var newCup = new Cup(id);
                cup.SetNext(newCup);
                cup = newCup;
            }
            cup = Extends(cup, max);
            cup.SetNext(start);

            return(new Circle(start));
        }
Example #6
0
 protected abstract Cup Extends(Cup cup, int max);
 protected override Cup Extends(Cup cup, int max)
 {
     return(cup);
 }