I am required to find the largest number in an integer array recursively. My function crashed but I cannot find the bug. Here's my c++ code:
void Numbers::compare(int size)
{
if(size == 0)
cout << "You must enter an number!" << endl;
if(size ==1)
cout << "The max number is " << numArray[0] << endl;
if(size >1)
{
if(numArray[size-1] > numArray[size-2])
{
int temp = 0;
numArray[size-1] = temp;
temp = numArray[size-2];
numArray[size-2]= numArray[size-1];
size --;
}
size = size -1 ;
compare(size);
}
}
Aucun commentaire:
Enregistrer un commentaire