Question: How would i write the siftUp and siftDown method? I can attach my HeapSortApp class as well if needed. ` ` ` import java.util.Comparator; public
How would i write the siftUp and siftDown method? I can attach my HeapSortApp class as well if needed.
import java.util.Comparator;
public class SortAlgorithms
public static void heapsortT records, Comparator c
for int i; i; k
T t recordsk;
recordsk records;
records t;
siftDownrecords k c;
printRecordsSorted Array:", records;
private static void siftDownT records, int k Comparator c
TODO ADD CODE HERE
private static void siftUpT records, int i Comparator c
TODO ADD CODE HERE
private static void printRecordsString hdr T records
System.out.printlnhdr;
forint i; i
import java.ioFile;
import java.ioFileNotFoundException;
import java.util.Scanner;
public class SortApp
public static void mainString args
StudentRecord records null;
try
records readRecordsFromFileargs;
catch FileNotFoundException e
System.err.printlnInput file not found.";
return;
printRecordsRecords read from input file:", records;
sort the records using in place heapsort
SortingAlgorithms.heapsortrecords new StudentRecordComparator;
printRecordsSorted records:", records;
private static StudentRecord readRecordsFromFileString inFileName
throws FileNotFoundException
Scanner sc new Scannernew FileinFileName;
int nRecords; number of records
int studentID;
String studentName;
StudentRecord records;
read number of records using scanner
nRecords scnextInt;
records new StudentRecordnRecords;
read each record using scanner
for int i; i
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
