about summary refs log tree commit diff
path: root/usth/ICT2.2/labwork/4/BubbleSort.java
blob: 8557c641d0a1f710c622846103f495b7b353f8f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.ArrayList;
import java.util.Scanner;

import static java.util.Collections.swap;

class Stats
{
  public static void main(String... args)
  {
    var scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    var numbers = new ArrayList<Double>();
    for (int i = 0; i < n; ++i)
      numbers.add(scanner.nextDouble());
    for (int m = 0; n > 1; n = m, m = 0)
      for (int i = 1; i < n; ++i)
        if (numbers.get(i).compareTo(numbers.get(i - 1)) < 0)
          swap(numbers, m = i, i - 1);
    System.out.println(numbers);
  }
}