Advertisement
Guest User

Untitled

a guest
Feb 7th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class insertionSort {
  5. public static void main(String[] args) {
  6. Scanner scan = new Scanner(System.in);
  7. String[] numbers = scan.nextLine().replace("[", "").replace("]", "")
  8. .split(", ");
  9. ArrayList<Integer> numbersArr = new ArrayList<Integer>();
  10.  
  11. for (int i = 0; i < numbers.length; i++) {
  12. numbersArr.add(Integer.parseInt(numbers[i]));
  13. }
  14.  
  15. for (int i = 1; i < numbersArr.size(); i++) {
  16. int bigNumber = numbersArr.get(i);
  17. int j = i;
  18. for (j = i; j > 0 && numbersArr.get(j - 1) > bigNumber; j--) {
  19. numbersArr.set(j, numbersArr.get(j - 1));
  20.  
  21. }
  22. numbersArr.set(j, bigNumber);
  23. }
  24. System.out.println(numbersArr);
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement