Find the second maximum in an array?

Answer Posted / vili

// this deals with negative numbers as well
int getSecondMax( int* pArray, int nSize )
{
int nMax = pArray[0];
int n2ndMax = pArray[0];
for ( int i = 1; i < nSize; i++ )
{
if ( nMax < pArray[i] )
{
n2ndMax = nMax;
n2ndMax = pArray[i];
}
}
return n2ndMax;
}

Is This Answer Correct ?    6 Yes 22 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is string data type in c++?

579


Is facebook written in c++?

558


When does the c++ compiler create temporary variables?

564


What is the importance of mutable keyword?

579


What is the use of lambda in c++?

571






What are files in c++?

587


What is meant by entry controlled loop? What all C++ loops are exit controlled?

558


What is a singleton c++?

545


How can virtual functions in c++ be implemented?

606


Are iterators pointers?

666


Why is null pointer used?

674


Define token in c++.

710


What is a manipulator in c++?

711


What is the arrow operator in c++?

556


What is a try block?

634