Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testproject;
- import java.util.Scanner;
- public class SelectionSortAlgorith {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int n = Integer.parseInt(input.nextLine());
- int[] numbers = new int[n];
- int elementIndex = 0;
- int container = 0;
- for (int i = 0; i < numbers.length; i++) {
- numbers[i] = input.nextInt();
- }
- int minElement = Integer.MAX_VALUE;
- for (int j = 0; j < numbers.length - 1; j++) {
- for (int i = j + 1; i < numbers.length; i++) {
- if (numbers[i] < numbers[j]) {
- if (numbers[i] < minElement) {
- minElement = numbers[i];
- elementIndex = i;
- }
- container = numbers[j];
- numbers[j] = numbers[elementIndex];
- numbers[elementIndex] = container;
- minElement = Integer.MAX_VALUE;
- }
- }
- }
- for (int i = 0; i < numbers.length; i++) {
- System.out.println(numbers[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement