Save the following java program into xxxxxH3.java and do as follow: DO NOT modify main method, except writing your name in line 82. Implement external sort: for sort phase use replacement selection...


Save the following java program into xxxxxH3.java and do as follow:



  1. DO NOT modify main method, except writing your name in line 82.

  2. Implement external sort:


for sort phase use replacement selection sort,


for merge phase use k-way merge to merge n sorted files F1.txt, F2.txt, ..., Fn.txt into F.txt.



  1. A sample input is as follow:Note: First input is max array size for sort



10 84 82 52 80 96 85 75 75 82 87 92 89 57 94 93 92 63 99 87


72 73 56 74 50 84 62 72 55 86 75 74 100 83 60 53 68 89 67 66


65 72 94 73 54 98 96 85 75 75 82 87 92 89


To compile: javacxxxxxh3.java


To execute: javaxxxxxh3




1 import java.util.*;



2 import java.io.*;



3 // CSUN COMP 282 Sp 21, Homework-3



4 // Implementing external sort:



5 // For sort phase using replacement selection sort



6 // and for merge phase using kway merge.



7 // Author: G. Dastghaiby Fard



8 public class xxxxxH3{



9 // class variables


10 int heap[][], M; // M is largest array size


11


12 //use a short word for System.out to save typing


13 PrintStream prt = System.out;


14


15 //print file formatted k integers per line


16 private void prtfile(String fn, int k){


17 //declare variables


18 int i=0, x;


19 prt.printf("\n\t%s:", fn);


20 try{


21 Scanner inf = new Scanner(new File(fn));


22 while (inf.hasNext()) {


23 //read an input from fname


24 x = inf.nextInt();


25 prt.printf("%3d ", x);


26 i++;


27 if(i % k == 0) prt.printf("\n\t");


28 } // endwhile


29 // close file


30 inf.close();


31 } catch (Exception e){


32 prt.printf("\nOoops! Read Exception: %s", e);}


33 } // end prtfile


34


35 // print n sorted files


36 private void prtfiles(int n, int k){


37 int i;


38 String fname ;


39 for (i = 1; i


40 fname = "F" +i+".txt";


41 prtfile(fname, k);


42 }


43 } // end prtfiles


44


45 // replacement selection sort, creating files


46 // larger than array size M


47 private int repselsort(){


48 // complete this method


49 // return no. of created files


50 } // end repselsort


51


52 // k-way merge n sorted files


53 // F1.txt, F2.txt, ..., Fn.txt into F.txt


54 private void kwaymerge(int n){


55 // complete this method


56 } // end kwaymerge


57


58 //Heapsort heap[][] with n integers


59 private void heapsort(int n){


60 //complete this method


61 } // end sort


62


63 public static void main(String[] args) throws Exception{


64 int n, k = 20;//print k data per line


65 xxxxxH3 srt = new xxxxxH3();


66


67 //apply replacement selection sort,


68 n = srt.repselsort();


69


70 //print n sorted files


71 srt.prtfiles(n, k);


72 System.out.printf("\n Overall %4d files are created", n);


73


74 //apply kwaymerge to merge n sorted files


75 //F1.txt, F2.txt, ..., Fn.txt into F.txt


76 srt.kwaymerge(n);


77


78 //print final sorted file


79 srt.prtfile("F.txt", k);


80


81 //MAKE SURE TO WRITE YOUR NAME IN NEXT LINE


82 System.out.printf("\n\tAuthor: Gh. Dastghaibyfard Date: " +


83 java.time.LocalDate.now());


84 } // end main


85 } // end xxxxxH3

Mar 30, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here