Sort algorithms take its time
Yepp, that's right. And if time really matters is that quicker?
int iMax = array[0]; //set min and max as the first element
int iMin = array[0];
for (int i=1; i<arraySize; i++)
{
if (array[i] < iMin)
iMin = array[i];
else
{
if (array[i] > iMax)
iMax = array[i];
}
}
int iMax = array[0]; //set min and max as the first element
int iMin = array[0];
for (int i=1; i<arraySize; i++)
{
if (array[i] < iMin)
iMin = array[i];
else
{
if (array[i] > iMax)
iMax = array[i];
}
}
To copy to clipboard, switch view to plain text mode
Because under circumstances (if array[i] < iMin) the second test isn't performed. If so the question of the day remains: Which is quicker?
int iMax = array[0]; //set min and max as the first element
int iMin = array[0];
for (int i=1; i<arraySize; i++)
{
if (array[i] < iMin)
iMin = array[i];
else
if (array[i] > iMax)
iMax = array[i];
}
int iMax = array[0]; //set min and max as the first element
int iMin = array[0];
for (int i=1; i<arraySize; i++)
{
if (array[i] < iMin)
iMin = array[i];
else
if (array[i] > iMax)
iMax = array[i];
}
To copy to clipboard, switch view to plain text mode
or
int iMax = array[0]; //set min and max as the first element
int iMin = array[0];
for (int i=1; i<arraySize; i++)
{
if (array[i] > iMax)
iMax = array[i];
else
if (array[i] < iMin)
iMin = array[i];
}
int iMax = array[0]; //set min and max as the first element
int iMin = array[0];
for (int i=1; i<arraySize; i++)
{
if (array[i] > iMax)
iMax = array[i];
else
if (array[i] < iMin)
iMin = array[i];
}
To copy to clipboard, switch view to plain text mode
Bookmarks