コード例 #1
0
        public void Add(Straw straw)
        {
            var maxValue      = 0;
            var selectedColor = Colors.Last();
            var colorSame     = true;
            int prevValue     = -1;

            foreach (var color in straw.ColorsWithValues)
            {
                colorSame = colorSame && (prevValue == -1 || prevValue == color.Value);
                prevValue = color.Value;
                if (maxValue < color.Value)
                {
                    maxValue      = color.Value;
                    selectedColor = color.Key;
                }
                else if (maxValue == color.Value && color.Key < selectedColor)
                {
                    maxValue      = color.Value;
                    selectedColor = color.Key;
                }
            }
            selectedColor = colorSame ? Color.Gray : selectedColor;
            var dictionary = SortedHay[selectedColor];

            if (!dictionary.Contains(straw.LengthInCm))
            {
                dictionary.Add(straw.LengthInCm, straw);
            }
        }
コード例 #2
0
 public void TreeAdd(SortedDictionary <decimal, Straw> tree, Straw straw)
 {
     if (!tree.ContainsKey(straw.LengthInCm))
     {
         tree.Add(straw.LengthInCm, straw);
     }
     return;
 }