Esempio n. 1
0
        public Cup FindNextLowerOrGreatest(int a_cupNumber, Cup a_removedCups)
        {
            Dictionary <int, Cup> removed = new Dictionary <int, Cup>();

            while (a_removedCups != null)
            {
                removed.Add(a_removedCups.Number, a_removedCups);
                a_removedCups = a_removedCups.Next;
            }

            int nextLower = a_cupNumber - 1;

            while (nextLower >= 1 && removed.ContainsKey(nextLower))
            {
                nextLower = nextLower - 1;
            }

            if (nextLower != 0)
            {
                return(m_cups[nextLower]);
            }

            int greatest = m_maxNummer;

            while (greatest >= 1 && removed.ContainsKey(greatest))
            {
                greatest = greatest - 1;
            }

            if (greatest != 0)
            {
                return(m_cups[greatest]);
            }
            return(null);
        }
Esempio n. 2
0
        public void InsertCups(Cup a_insertAfter, Cup a_cupsToInsert)
        {
            var lastCup = a_cupsToInsert;

            while (lastCup.Next != null)
            {
                lastCup = lastCup.Next;
            }

            lastCup.Next       = a_insertAfter.Next;
            a_insertAfter.Next = a_cupsToInsert;
        }
Esempio n. 3
0
        public static Ring Create(string a_line, int a_fillUpTo)
        {
            var ring      = new Ring();
            int maxNummer = 0;
            var cups      = new List <Cup>();

            foreach (var strNum in a_line.ToCharArray())
            {
                if (!int.TryParse($"{strNum}", out var nummer))
                {
                    return(null);
                }
                if (nummer > maxNummer)
                {
                    maxNummer = nummer;
                }

                var newCup = new Cup(nummer);
                cups.Add(newCup);
                ring.m_cups.Add(nummer, newCup);
            }

            for (int additional = maxNummer + 1; additional <= a_fillUpTo; additional++)
            {
                var newCup = new Cup(additional);
                cups.Add(newCup);
                ring.m_cups.Add(additional, newCup);
            }

            if (a_fillUpTo > maxNummer)
            {
                ring.m_maxNummer = a_fillUpTo;
            }
            else
            {
                ring.m_maxNummer = maxNummer;
            }

            for (int i = 0; i < cups.Count; i++)
            {
                if (i != cups.Count - 1)
                {
                    cups[i].Next = cups[i + 1];
                }
                else
                {
                    cups[i].Next = cups[0];
                }
            }

            ring.CurrentCup = cups[0];
            return(ring);
        }
Esempio n. 4
0
 public void StepToNext()
 {
     CurrentCup = CurrentCup.Next;
 }