Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i want flowchart of this code import java.util.Scanner; public class MinHeap { public static void main ( String [ ] args ) { int arrSize
i want flowchart of this code import java.util.Scanner;
public class MinHeap
public static void mainString args
int arrSize ;
Scanner in new ScannerSystemin;
System.out.printEnter the size of the array you want to construct: ;
arrSize innextInt;
int A new intarrSize;
whiletrue
System.out.println Insert
Delete
Search
Print sorted array the array size and sort time to the screen
Quit";
long start ;
int data ;
System.out.printEnter your choice: ;
switchinnextInt
case :
start System.currentTimeMillis;
forint i arrSize ; i ; i
Ai i ;
System.out.printlnIt took you doubleSystemcurrentTimeMillis start seconds to insert data.";
break;
case :
System.out.printEnter the data to delete: ;
data innextInt;
start System.currentTimeMillis;
arrSize deleteA arrSize, data;
System.out.printlnIt took you doubleSystemcurrentTimeMillis start seconds to delete data.";
break;
case :
System.out.printEnter the data to search: ;
data innextInt;
start System.currentTimeMillis;
searchA arrSize, data;
System.out.printlnIt took you doubleSystemcurrentTimeMillis start seconds to search data.";
break;
case :
start System.currentTimeMillis;
MinHeap ob new MinHeap;
obsortA;
System.out.printlnIt took you doubleSystemcurrentTimeMillis start seconds to sort data.";
start System.currentTimeMillis;
printSortedArrayA;
System.out.printlnIt took you doubleSystemcurrentTimeMillis start seconds to print data.";
break;
case :
default:
System.exit;
private static void searchint A int arrSize, int data
forint i ; i arrSize; i
ifAi data
System.out.printlnData data found at index i ;
return;
private static int deleteint A int arrSize, int data
boolean isDelete false;
forint i ; i arrSize; i
ifAi data
isDelete true;
arrSize;
private void sortint A
int n Alength;
for int i n ; i ; i
makeHeapA n i;
for int i n ; i ; i
int temporary A;
A Ai;
Ai temporary;
makeHeapA i;
private void makeHeapint A int n int i
int largest i;
int leftchild i ;
int rightchild i ;
if leftchild n && Aleftchild Alargest
largest leftchild;
if rightchild n && Arightchild Alargest
largest rightchild;
if largest i
int swap Ai;
Ai Alargest;
Alargest swap;
makeHeapA n largest;
private static void printSortedArrayint A
System.out.printSorted array: ;
int n Alength;
for int i ; i n; i
System.out.printAi;
System.out.println;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started