예제 #1
0
 private void PutDownRestOfTheElements()
 {
     foreach (var el in ElementsUp.Skip(1).SkipLast(1).ToList())
     {
         NumbersWithConnections.Add(el.Item1, el.Item2);
     }
 }
예제 #2
0
        private void RestoreLinksOriginalDestinationNextElement(int originalNextDestination)
        {
            var lastUp = ElementsUp.Last();
            var destinationNextLinks = NumbersWithConnections[originalNextDestination];

            NumbersWithConnections.Add(lastUp.Item1, new Tuple <int, int>(lastUp.Item2.Item1, originalNextDestination));
            NumbersWithConnections[originalNextDestination] = new Tuple <int, int>(lastUp.Item1, destinationNextLinks.Item2);
        }
예제 #3
0
        public void PutElementsUp()
        {
            var nextToPutUp = NumbersWithConnections[TargetNumber].Item2;

            for (int i = 0; i < skippedElements; i++)
            {
                var elementToPutUp = NumbersWithConnections[nextToPutUp];
                NumbersWithConnections.Remove(nextToPutUp);
                ElementsUp.Add(new Tuple <int, Tuple <int, int> >(nextToPutUp, elementToPutUp));
                nextToPutUp = elementToPutUp.Item2;
            }
        }
예제 #4
0
        private void RestoreDestinationLinks()
        {
            var firstUp          = ElementsUp.First();
            var destinationLinks = NumbersWithConnections[DestinationNumber];

            if (ElementsUp.Last().Item1 == destinationLinks.Item1)
            {
                destinationLinks = new Tuple <int, int>(firstUp.Item2.Item1, destinationLinks.Item2);
            }

            NumbersWithConnections.Add(firstUp.Item1, new Tuple <int, int>(DestinationNumber, firstUp.Item2.Item2));
            NumbersWithConnections[DestinationNumber] = new Tuple <int, int>(destinationLinks.Item1, firstUp.Item1);
        }
예제 #5
0
        public void SetDestination()
        {
            var localTarget = TargetNumber - 1;

            for (; localTarget > 0; localTarget--)
            {
                if (NumbersWithConnections.ContainsKey(localTarget))
                {
                    DestinationNumber = localTarget;
                    return;
                }
            }
            DestinationNumber = NumbersWithConnections.Max(k => k.Key);
        }