• File: Cocktail.java
  • Full Path: /home/lmnet/fm-site/files/JavaProgramming/JAVAPROGRAMS/Sorting_System/Cocktail.java
  • Date Modified: 10/28/2025 3:54 AM
  • File size: 2.17 KB
  • MIME-type: text/x-java
  • Charset: utf-8
 
Open Back
//Coded by Gabriel Riogelon 


import java.util.*;
public class Cocktail {
    public static void main(String[] args){
        double temp;
        int check = 0;
        double st[] = new double[args.length];
        for (int i = 0; i < args.length;i++){
            st[i] = Double.parseDouble(args[i]);
        }
        sorting:
        while(true){
            for (int i = 0; i < st.length-1;i++){
                if(st[i] > st[i+1]){
                    temp = st[i];
                    st[i] = st[i+1];
                    st[i+1] = temp;
                    System.out.println(Arrays.toString(st)+"\n");
                }
            }
            for (int i = st.length-2; i >= 0;i--){
                if(st[i] > st[i+1]){
                    temp = st[i];
                    st[i] = st[i+1];
                    st[i+1] = temp;
                    System.out.println(Arrays.toString(st)+"\n");
                }   
            }
            for (int i = 0; i < st.length-1;i++){
                check++;
                if(st[i] > st[i+1]){
                    check = 0;
                    continue sorting;
                }
            }
            if(check == st.length-1){
                break;
            }
        }
    }
}
//Copy this args: 5427.14 1507.54 9045.23 703.52 4623.12 9648.24 7286.43 5829.15 201.01 4824.12 2512.56 3668.34 3768.84 9447.24 2713.57 4271.36 2060.30 3165.83 1256.28 603.02 2964.82 6482.41 482.51 1809.05 6080.40 904.52 3567.84 5025.13 3668.34 995.03 2110.55 6633.17 5125.63 8140.70 9296.48 9045.23 5527.64 7386.93 9648.24 7135.68 6030.15 7336.68 9045.23 6683.42 8743.72 9045.23 4824.12 351.76 904.52 9246.23 4572.86 4974.87 0.00 3517.59 10000.00 6532.66 2864.32 4170.85 8040.20 4924.62 4170.85 8492.46 5175.88 3015.08 9346.73 1105.53 1859.30 301.51 6331.66 3517.59 9447.24 3768.84 8793.97 5427.14 9145.73 904.52 5175.88 9648.24 8040.20 6231.16 6180.90 3216.08 2361.81 3266.33 9547.74 9648.24 8743.72 2864.32 3216.08 7185.93 7035.18 2060.30 9045.23 7135.68 9648.24 4723.62 2512.56 995.03 5025.13 8944.72 9748.74 9648.24 1256.28 9045.23 995.03 8040.20 9648.24 9447.24 5175.88 9346.73 9547.74 9648.24 9045.23 4824.12 9648.24 9447.24 301.51 5427.14 1256.28 8743.72 9648.24