Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sorting
- {
- public static void main(String[] args)
- {
- sort();
- }
- public static void sort()
- {
- int[] input = { 10, 6, 8, 9, 0, 12, 1, 4, 2, 11, 5, 3, 13, 14, 7};
- int counter = 0;
- System.out.println("******Unsorted array******");
- for (int i = 0; i < input.length; i++)
- {
- System.out.println("input[" + i + "] is " + input[i]);
- }
- boolean sorted = false;
- while (!sorted)
- {
- counter = 0;
- for (int i = 0; i < input.length; i++)
- {
- if (counter == input.length - 1)
- {
- sorted = true;
- }
- else
- {
- sorted = false;
- }
- int v1 = 0, v2 = 0;
- if (i < input.length - 1)
- {
- if (input[i + 1] < input[i])
- {
- v2 = input[i];
- v1 = input[i + 1];
- input[i] = v1;
- input[i + 1] = v2;
- }
- else
- {
- counter++;
- }
- }
- }
- }
- System.out.println("******Sorted array******");
- for (int i = 0; i < input.length; i++)
- {
- System.out.println("input[" + i + "] is " + input[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment