This is a tough one i am doing a partion sort but the trick

This is a tough one

i am doing a partion sort but the trick here is, that it is in fraction form

therefore my teacher is going to enter a string   \"3/4 33/4 2/5 3/9 22/5 10/3\"

and i have to display the string sorted so basically \"8 1/4, 3/9, 4 2/5, 3/4, 3/10\" (in order )

i\'m not looking for someone to do it for me but anything helps for example

what code do i use to read the \"\\\" i know how to read integers off a string and convert them to integers with parseInt,

but now that there is a \"\\\" things got more complicated.

can i create an array that can store a value of \"1/3\" or \"1 1/3\"

i have the idea i\'m going to take num, and dem, and use % to get remainders and / to divide

i need to count the number of fractions the string contains as well so

help with that is what i mostly need, thank you!!! who ever can is the master!

Solution

Rather than taking numerator and denominator it will be prefer to use the concept of reading the line as string and then converting into integers by using the ascii conversion..

First read the string character by character and then untill the symbol is occured read and convert it to integer and then read until space and convert it to integer, Now using array to store these value is possible by creating float array rather than integer array and consider the decimal point to be 3 or 4 as your wish continue the process untill all the characters have been read and converted

This is a tough one i am doing a partion sort but the trick here is, that it is in fraction form therefore my teacher is going to enter a string \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site