Question

Pseudocode to code in java. Pseudocode: ARRAY a e..n] . min = 0 · max = n WHILE (max > min) (j = min . .max) IF FOR (a[j] 〈 a[min]) swap(a, j, min) END-IF IF (a[j] 〉 a[max ] ) swap(a, j, max) END-IF END- FOR min min + 1 max = max-1 END-WHILE

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code using java

---------------------------------------------------------------------------------------------------------------------------------------------

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package max_min_java;

/**
*
* @author Kamal
*/
public class Max_min_java {

/**
* @param args the command line arguments
*/
static void swap(int arr[],int i,int j)
{
int temp;
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
public static void main(String[] args) {
// TODO code application logic here
  
int arr[]={1,2,30,50,6,7,8};
int n=arr.length-1;
System.out.println(n);

int min=0;
int max=n;
int j;
while(max>min)
{
for(j=min;j<=max;j++)
{
if(arr[j]<arr[min])
swap(arr,j,min);
if(arr[j]>arr[max])
swap(arr,j,max);
}
min=min+1;
max=max-1;
  
}
System.out.println("min value is " +min);
System.out.println("max value is "+max);
  
}
  
}

--------------------------------------------------------------------------------------------------------------------------------------------

Output

max min java - NetBeans IDE 8.2 File Edit View Navigate Source Refactor Run Debug Profie Teem Iools Window Help Search (Ct1+)

Add a comment
Know the answer?
Add Answer to:
Pseudocode to code in java . Pseudocode: ARRAY a e..n] . min = 0 · max...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT