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

Difference between declaration and definition of a variable.

589


Can constructor be static in c++?

643


What are the differences between the function prototype and the function defi-nition?

626


What is the extraction operator and what does it do?

614


When does the c++ compiler create temporary variables?

575






Explain what are mutator methods in c++?

572


How to access a variable of the structure?

585


How do you remove an element from a set in c++?

584


What do the header files usually contains?

636


Comment on c++ standard exceptions?

640


Which programming language is best?

558


What is constant in c++ with example?

614


Differentiate between an external iterator and an internal iterator? What is the advantage of an external iterator.

620


What are the uses of static class data?

638


what is a reference variable in C++?

670