From e4a47373030ccdcc7085ecd5469286048bb22835 Mon Sep 17 00:00:00 2001 From: Gyuseok Kim <34904741+kim6394@users.noreply.github.com> Date: Sat, 16 Nov 2019 09:15:38 +0900 Subject: [PATCH] 2019-11-16 [Algorithm] bubbleSort code Add --- Algorithm/code/bubbleSort.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Algorithm/code/bubbleSort.java diff --git a/Algorithm/code/bubbleSort.java b/Algorithm/code/bubbleSort.java new file mode 100644 index 00000000..93ee323c --- /dev/null +++ b/Algorithm/code/bubbleSort.java @@ -0,0 +1,13 @@ +void bubbleSort(int[] arr) { + int temp = 0; + for(int i = 0; i < arr.length; i++) { + for(int j= 1 ; j < arr.length-i; j++) { + if(arr[j-1] > arr[j]) { + temp = arr[j-1]; + arr[j-1] = arr[j]; + arr[j] = temp; + } + } + } + System.out.println(Arrays.toString(arr)); +}