diff --git a/src/com/rkcsd/apps/demo/BubbleSort.java b/src/com/rkcsd/apps/demo/BubbleSort.java new file mode 100644 index 0000000..14838be --- /dev/null +++ b/src/com/rkcsd/apps/demo/BubbleSort.java @@ -0,0 +1,34 @@ +package com.rkcsd.apps.demo; + +import java.util.Arrays; + +public class BubbleSort { + static int[] arr = {24, -7, -123456, -25, -64, 555, 3234}; + + public static void main(String[] args) { + + + System.out.println(Arrays.toString(BubbleSort.sort(arr))); + + } + + public static int[] sort(int[] a){ + int tmp; + + for (int i = a.length - 1; i >= 0; i--) { + + for (int j = 0; j <= i - 1; j++) { + + if (a[j] > a[j + 1]) { + tmp = a[j]; + a[j] = a[j + 1]; + a[j + 1] = tmp; + } + + } + + } + return a; + } +} +