HackerRank/Problem-Solving/InsertionSortPart1.cpp
// Complete the insertionSort1 function below.
Complete the insertionSort1 function below.
Complete the insertionSort1 function below .
void insertionSort1(int n, vector<int> arr)
{
    for (int i = 1; i < n; i++)
    {
        int key = arr[i];
        int j = i - 1;
        while (j >= 0 && arr[j] > key)
        {
            arr[j + 1] = arr[j];
            j--;
            for (int k = 0; k < n; k++)
                cout << arr[k] << " ";
            cout << endl;
        }
        arr[j + 1] = key;
    }
    for (int k = 0; k < n; k++)
        cout << arr[k] << " ";
    cout << endl;
}
void insertionSort1 ( int n , vector < int > arr ) { for ( int i = 1 ; i < n ; i ++ ) { int key = arr [ i ] ; int j = i - 1 ; while ( j >= 0 && arr [ j ] > key ) { arr [ j + 1 ] = arr [ j ] ; j -- ; for ( int k = 0 ; k < n ; k ++ ) cout << arr [ k ] << " " ; cout << endl ; } arr [ j + 1 ] = key ; } for ( int k = 0 ; k < n ; k ++ ) cout << arr [ k ] << " " ; cout << endl ; }
Complete the insertionSort1 function below.
Complete the insertionSort1 function below .