Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you make a heapsort for fractions using the logic in the pictures and instructions in the first picture. I provided a dividing fraction code

Can you make a heapsort for fractions using the logic in the pictures and instructions in the first picture. I provided a dividing fraction code in java which should be used in making the heapsort. If you can't understand the logic on the whiteboard can you just do a heapsort for fractions your own way of course using the code I gave.

image text in transcribedimage text in transcribed

image text in transcribedimage text in transcribed

package test;

//return gcd public class Utility {

public static String clean ( String s ) { int numerator; String s1[] = s.split(", "); for(int i = 0; i

//test public class Test {

public static void main(String[] args) { //fractions Fraction g=new Fraction(2,8); Fraction f= new Fraction("3/4"); //print original System.out.println("Orig="+f+","+g); //call the function Fraction[]quotient_remainder=Fraction.divFract(f,g); //print after System.out.println("After="+f+","+g); //print Quotient & Remainder System.out.println("Quotient & Remainder="+quotient_remainder[0]+","+ quotient_remainder[1]); } }

//fraction class public class Fraction {

int num, den;

//constructor public Fraction(int num, int den) { this.num = num; this.den = den; }

//constructor with string as parameter public Fraction(String fract) { int integral,num,den; //if mixed fraction, split the string try{ String[]number = fract.split(" "); integral = Integer.parseInt(number[0]); String[] num_dun = number[1].split("/"); num = Integer.parseInt(num_dun[0]); den = Integer.parseInt(num_dun[1]); num = integral*den+num; } //if fraction is regular, catch the error and proceed with alternate code catch(NumberFormatException e) { String[] num_dun = fract.split("/"); num = Integer.parseInt(num_dun[0]); den = Integer.parseInt(num_dun[1]); } //set num , den this.num = num; this.den = den;

}

//divide fraction public static Fraction[] divFract(Fraction f, Fraction g) { int num_div = f.num * g.den; int den_div = f.den * g.num; int gcd = Utility.findGCD(num_div, den_div); num_div/=gcd; den_div/=gcd;

f.num = num_div; f.den = den_div; int quotient = num_div/den_div; int remainder = num_div % den_div; Fraction[] retValue = {new Fraction(quotient, 1), new Fraction(remainder, 1)}; return retValue; }

//return string public String toString() { if(den==1) return num+""; else return num+"/"+den; } }

O x + v & 1 C A Person Is Rotated In A Ho Page mv: WebClass Program 3.pdf O c 5182.00.csun.edu/LECTURES/wa/Program%203.pdf of 1 1 0 - + Fit to page Page view A Read aloud Add notes 6 % Program 3: Heap Sort on Fractions, Due on Feb 28, 2020 50 point bonus Please follow the following instructions before turning in your USB 1. Your U5B will have a label from outside under YourLastName_FirstName 2. Inside your USB there is a FOLDER under the name: Your LastName FirstName P3. 3. Inside the above folder, a. There are only the source codes. There will be NO files with suffix class. b. The first line in each file must bear your full name after the double slashes // 4. Your instructor will compile your files and run Test.class via cmd/terminal. Your must be responsible to make sure your files are standard to run properly. Your instructor WILL NOT touch your files. Your instructor will make his own Test file to evaluate all students' performance 5. Conditions: You must follow the lecture in cless to implement HeapSort on Fractions in order to be granted the bonus. Here is a sample of the instructions (caller) in Test.java: //read from keyboard a string such as 5-' 2,3/4, 1/16, 23/2,2 2/4...15/2.," //create an object such as HeapsortsP obj - new HeapsortSP(s; //sort: obj.heapSortSpo: 1/Print: System.out.println("Fractions in increasing order - obil: 6. Note: SP are the initials of your instructor. You need to replace they by yours. O Type here to search o ese A . 4 of 6:47 PM 1/24/2020 x + v - X Search Textbook Solutions Page mv: WebClass 20200215_150536.jpg 5182.ecs.csun.edu/LECTURES/Wk4/wk4 Saturday/20200215_150536.jpg E 0 langut BULLY - - | Swap 168 16 bir Water Sooked areas prek #2 percolate 1400 1 percuintes eink 1 - 3 Bow me paren (1) = I child : [26] 2 : 12:40 Follow the kalang to m e je to the why not w 119 due. 2/28/2006 ! Hornst To match with any Index Went do not wemost all extra vernielde touch composte trap St "aqits * Find the last parent (o. length - 1) 2 INEX 6:50 PM 5 Type here to search 0 * O e SOS 2/24/2020 x + v - X Search Textbook Solutions Page mv: WebClass 20200215_155556.jpg 5182.ecs.csun.edu/LECTURES/Wk4/wk4 Saturday/20200215_155556.jpg E 0 perco late (int i, int barrier) { is wild Heap & II int childt nei int tempt ail forl ; 20i banter; is chile) { ifl a[child']

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started