how do i convert the min_max function to the method of the IntArray class?
class IntArray
{private :
int a[];
int n;
..........
};
void min_max(int n,int a[],int&mini,int &maxi)
{
mini=a[0];
maxi=a[0];
for (int i=1; i<n; i++)
{
if (mini>a[i])
mini=a[i];
if (maxi<a[i])
maxi=a[i];
class IntArray
{
private:
int a[];
int n;
public:
void min_max(int &mini, int &maxi)
{
mini = a[0];
maxi = a[0];
for (int i = 1; i < n; i++)
{
if (mini > a[i])
mini = a[i];
if (maxi < a[i])
maxi = a[i];
}
}
};
But see my suggestion in the other thread to return the index in mini and maxi instead of the value.
Note that I don't pass n or a to the method. The method will use the n and a members of the class.