Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class insertionSort {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String[] numbers = scan.nextLine().replace("[", "").replace("]", "")
- .split(", ");
- ArrayList<Integer> numbersArr = new ArrayList<Integer>();
- for (int i = 0; i < numbers.length; i++) {
- numbersArr.add(Integer.parseInt(numbers[i]));
- }
- for (int i = 1; i < numbersArr.size(); i++) {
- int bigNumber = numbersArr.get(i);
- int j = i;
- for (j = i; j > 0 && numbersArr.get(j - 1) > bigNumber; j--) {
- numbersArr.set(j, numbersArr.get(j - 1));
- }
- numbersArr.set(j, bigNumber);
- }
- System.out.println(numbersArr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement