Пример #1
0
 public bool FirstStepSwapAdj(Element[] elements)
 {
     Element largestMobile = GetLargestMobile(elements);
     if (largestMobile.Value == -1)
     {
         return false;
     }
     Swap(elements, largestMobile);
     return true;
 }
Пример #2
0
 public void FigureOutRight(Element element, int i, Element[] elements, Element largest)
 {
     if (i == (elements.Length - 1))
     {
         //not mobile = is last and point to right
     }
     else
     {
         int rightIndex = i + 1;
         if (element.Value > elements[rightIndex].Value && element.Value > largest.Value)
         {
             largest.Value = element.Value;
             largest.Position = element.Position;
         }
     }
 }
Пример #3
0
 public void FigureOutLeft(Element element, int i, Element[] elements, Element largest)
 {
     if (i == 0)
     {
         //not mobile = is first and point to left
     }
     else
     {
         int leftIndex = i - 1;
         if (element.Value > elements[leftIndex].Value && element.Value > largest.Value)
         {
             largest.Value = element.Value;
             largest.Position = element.Position;
         }
     }
 }
Пример #4
0
 public Element GetLargestMobile(Element[] elements)
 {
     Element largest = new Element() {  Value = -1, Position = Enums.Positions.Left };
     for (int i = 0; i < elements.Length; i++)
     {
         var element = elements[i];
         if (element.Position == Enums.Positions.Left)
         {
             FigureOutLeft(element, i, elements, largest);
         }
         if (element.Position == Enums.Positions.Right)
         {
             FigureOutRight(element, i, elements, largest);
         }
     }
     return largest;
 }
Пример #5
0
 private void SwapElementDirection(Element element)
 {
     if (element.Position == Enums.Positions.Left)
     {
         element.Position = Enums.Positions.Right;
     }
     else
     {
         element.Position = Enums.Positions.Left;
     }
 }
Пример #6
0
 private void Swap(Element[] elements, Element largestMobile)
 {
     int largestPosition = elements.GetIndex(largestMobile);
     if (largestMobile.Position == Enums.Positions.Left)
     {
         elements.SwapLeft(largestMobile, largestPosition);
     }
     if (largestMobile.Position == Enums.Positions.Right)
     {
         elements.SwapRight(largestMobile, largestPosition);
     }
 }
Пример #7
0
 private Element[] MakeCopy(Element[] orderedElements)
 {
     var elemnts = new Element[orderedElements.Length];
     for (int i = 0; i < orderedElements.Length; i++)
     {
         var e = orderedElements[i];
         elemnts[i] = e;
     }
     return elemnts;
 }
Пример #8
0
 private bool IsThereNumberBiggerThan(Element currentLargest, Element[] orderedElements)
 {
     foreach (var item in orderedElements)
     {
         if (item.Value > currentLargest.Value)
         {
             return true;
         }
     }
     return false;
 }