I need to come up with the pseudocode for a min and max value finder for an array, uses recursion. first I started writing a java program to get a better understanding but it seams not to work properly. also Im having trouble calculating the time efficiency for the code.
public class Max_min {
/**
* @param args the command line
arguments
*/
static int Max;
static int Min;
static int index;
static boolean b =true;
static String answer;
public static void main(String[] args) {
int[] array={1,10,2,8,3,22,7};
int val=0;
System.out.println
(find_min_max(array,val));
}
public static String find_min_max(int a[],int x)
{
index = Arrays.binarySearch(a, x);
if (a[x] > Max)
{
Max = a[x];
}
if (a[x] <= Min)
{
Min = a[x];
}
{
if(index < a.length)
{
find_min_max(a,(x+1));
}
return answer = "the max is "+ Max +" the min Value is
"+Min;
}
public class Max_min {
/**
* @param args the command line arguments
*/
static int Max;
static int Min;
static int index;
static boolean b =true;
static String answer;
public static void main(String[] args) {
int[] array={1,10,2,8,3,22,7};
int val=0;
System.out.println (find_min_max(array,val));
}
public static String find_min_max(int a[],int x)
{
//index = Arrays.binarySearch(a, x);
if(x==0)
{
Max=Min = a[x];
}
if(x == a.length)
return answer = "the max is "+ Max +" the min Value is "+Min;
if (a[x] > Max)
{
Max = a[x];
}
if (a[x] <= Min)
{
Min = a[x];
}
find_min_max(a,(x+1));
return answer = "the max is "+ Max +" the min Value is
"+Min;
}
}
Get Answers For Free
Most questions answered within 1 hours.