It is necessary to read data from a file using BufferedReader, select an array of numbers from the source data and produce a bucket sort. The problem with the selection of empty lines. Code:

public class new_1 { public static ArrayList<Double> bucketSort (ArrayList<Double> v, double minVal, double maxVal) { if ((v.size() <= 1) || (minVal == maxVal)) return v; else { ArrayList<Double> fb = new ArrayList<Double>(); ArrayList<Double> sb = new ArrayList<Double>(); double mid = (minVal+maxVal)/2; double minVal2 = Double.MAX_VALUE, maxVal2 = Double.MIN_VALUE; for (int i = 0; i < v.size(); i++) { Double cur = v.get(i); if (cur <= mid) { fb.add(cur); if (cur >= maxVal2) maxVal2 = cur; } else { sb.add(cur); if (cur <= minVal2) minVal2 = cur; } } fb = bucketSort(fb, minVal, maxVal2); sb = bucketSort(sb, minVal2, maxVal); for (int i = 0; i < sb.size(); i++) { fb.add(sb.get(i)); } return fb; } } public static void printResults(ArrayList<Double> a) { for (int i = 0; i < a.size(); i++) { System.out.println(a.get(i)); } } public static void main(String[] args) { String str[] = new String[49]; try { BufferedReader br = new BufferedReader(new FileReader("/123")); String all = ""; ArrayList<String> allLines = new ArrayList<String>(); while (true) { allLines.add(br.readLine()); } for (int i=0; i<allLines.size(); i++) { all = all + allLines.get(i); } if (all == "0") { System.out.println("File doesn`t have arguments. Please write some arguments in /home/s225030/123"); System.exit(1); } str = all.split(" "); } catch (Exception ex) { System.out.println("Error"); } if (str.length < 49) { System.out.println("File consist of less than 49 arguments. Please write 49 or more arguments"); System.exit(2); } if (str.length > 49){ System.out.println("File consist of more than 49 arguments. For arguments I get last 49 arguments"); } ArrayList<Double> iscom = new ArrayList<Double>(); double[] pereh = new double[49]; for (int i=0; i < 49; i++){ iscom.add(0.0); try { pereh[i] = Double.parseDouble(str[i]); iscom.set(i, pereh[i]); } catch (Exception e) { System.out.println("Wrong arguments"); System.exit(3); } } double minVal = Double.MAX_VALUE, maxVal = Double.MIN_VALUE; for (int i = 0; i < 49; i++) { double cur = iscom.get(i); if (cur < minVal) minVal = cur; if (cur > maxVal) maxVal = cur; } iscom = bucketSort(iscom, minVal, maxVal); printResults(iscom); } } 
  • Classes in Java are usually called with a capital letter and camel style. - Yuriy SPb
  • Thank you, I will consider this - A. Nikolaev

0