Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static class extraFraction{
- private int num;
- private int denom;
- private double decimal;
- private extraFraction(){
- num = 0;
- denom = 1;
- decimal = 0;
- }
- public extraFraction(int n, int d)
- {
- num = n;
- denom = d;
- decimal = ((double)n)/d;
- }
- public double getDecimal()
- {
- return decimal;
- }
- public int gn(){
- return num;
- }
- public int gd(){
- return denom;
- }
- public String toString()
- {
- String s1;
- s1 = ""+num + "/" + denom;
- return s1;
- }
- }
- public static void FractionSort()
- {
- ArrayList<extraFraction> values = new ArrayList<extraFraction>();
- for (int i = 0; i < list.size(); i++)
- {
- int n = list.get(i).getNumerator();
- int d = list.get(i).getDenominator();
- extraFraction newer = new extraFraction(n,d);
- values.add(newer);
- }
- for (int i = 0; i < list.size(); i++)
- {
- for (int j = 0; j <= i; j++)
- {
- if (values.get(j).getDecimal()>values.get(i).getDecimal())
- {
- extraFraction oldfrac = values.set(j+1, values.get(j));
- values.set(j+1, values.get(j));
- values.add(j, oldfrac);
- }
- }
- }
- for (int i = 0 ; i < list.size(); i++)
- {
- System.out.println((i + 1) + ".\t" + values.get(i));
- }
- r.pause();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement