Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Sorting;
- import java.util.Arrays;
- public class bubbleSort {
- public static void swap(int[] x, int i, int j)
- {
- int temp = x[i];
- x[i] = x[j];
- x[j] = temp;
- }
- public static void bubbleSort(int x[])
- {
- for (int j = 0; j < x.length -1; j++)
- {
- for (int i = 0; i < x.length - 1 - j; i++)
- {
- if (x[i] > x[i + 1])
- {
- swap(x, i, i + 1);
- }
- }
- }
- }
- public static void main(String[] args) {
- int x[] = {3, 2, 6, 8, 5, 1};
- bubbleSort(x);
- System.out.println(Arrays.toString(x));
- }
- }
Add Comment
Please, Sign In to add comment