mardi 17 mars 2020

C++ -- InsertionSort Loses One Array Element

  • When I use my class slides to write the Method, the last string in the array disappears.
  • When I use "GeeksFromGeeks" pseudocode, it's the first string that gets chopped off somehow.
  • I'm unable to identify what is wrong with my Method:

InsertionSort Algorithm:

void inSertionSortFct(string* theArray, int arrSize) 
{     
    int i, j;  
    string keyStry;

    for( i = 1; i < arrSize; i++) 
    {
        keyStr = theArray[i];
        j = i - 1;

        while( j >= 0 && theArray[j] > keyStr )
        {
            theArray[j+1] = theArray[j];
            j = j - 1;
        }
        theArray[j+1] = keyStr;
    }   
} 

Aucun commentaire:

Enregistrer un commentaire