Skip to main content
added 20 characters in body
Source Link
paparazzo
  • 6.1k
  • 3
  • 20
  • 43

Can use a for for the counter and eliminate a lot of the counters

public static void insertionSort(int[] unsortedArray)
{
    int unsortedElementlastIndex = unsortedArray.[unsortedArray.Count()Length - 1];1;
    for (int iunsortedElement = unsortedArray.Count[lastIndex ];
    for ()int -i 1;= lastIndex; i >= 0; i--)
    {
        if (i == 0)
        {
            unsortedArray[i] = unsortedElement;
            printArray(unsortedArray);
        }
        else if(unsortedArray[i - 1] > unsortedElement)
        {        
            unsortedArray[i] = unsortedArray[i - 1];
            printArray(unsortedArray);
        }
        else
        {
            unsortedArray[i] = unsortedElement;
            printArray(unsortedArray);
            break;
        }
    }
}

Can use a for for the counter

public static void insertionSort(int[] unsortedArray)
{
    int unsortedElement = unsortedArray.[unsortedArray.Count() - 1];
    for (int i = unsortedArray.Count() - 1; i >= 0; i--)
    {
        if (i == 0)
        {
            unsortedArray[i] = unsortedElement;
            printArray(unsortedArray);
        }
        else if(unsortedArray[i - 1] > unsortedElement)
        {        
            unsortedArray[i] = unsortedArray[i - 1];
            printArray(unsortedArray);
        }
        else
        {
            unsortedArray[i] = unsortedElement;
            printArray(unsortedArray);
            break;
        }
    }
}

Can use a for for the counter and eliminate a lot of the counters

public static void insertionSort(int[] unsortedArray)
{
    int lastIndex = unsortedArray.Length - 1;
    int unsortedElement = unsortedArray.[lastIndex ];
    for (int i = lastIndex; i >= 0; i--)
    {
        if (i == 0)
        {
            unsortedArray[i] = unsortedElement;
            printArray(unsortedArray);
        }
        else if(unsortedArray[i - 1] > unsortedElement)
        {        
            unsortedArray[i] = unsortedArray[i - 1];
            printArray(unsortedArray);
        }
        else
        {
            unsortedArray[i] = unsortedElement;
            printArray(unsortedArray);
            break;
        }
    }
}
Source Link
paparazzo
  • 6.1k
  • 3
  • 20
  • 43

Can use a for for the counter

public static void insertionSort(int[] unsortedArray)
{
    int unsortedElement = unsortedArray.[unsortedArray.Count() - 1];
    for (int i = unsortedArray.Count() - 1; i >= 0; i--)
    {
        if (i == 0)
        {
            unsortedArray[i] = unsortedElement;
            printArray(unsortedArray);
        }
        else if(unsortedArray[i - 1] > unsortedElement)
        {        
            unsortedArray[i] = unsortedArray[i - 1];
            printArray(unsortedArray);
        }
        else
        {
            unsortedArray[i] = unsortedElement;
            printArray(unsortedArray);
            break;
        }
    }
}