From ab0918d16dd64bad4facc4bb5542c88b99d8a9d0 Mon Sep 17 00:00:00 2001 From: kartik-manchanda Date: Thu, 1 Oct 2020 12:39:59 +0530 Subject: [PATCH] added bubbleSort Program --- src/chapter10sorting/BubbleSort.java.txt | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/chapter10sorting/BubbleSort.java.txt diff --git a/src/chapter10sorting/BubbleSort.java.txt b/src/chapter10sorting/BubbleSort.java.txt new file mode 100644 index 0000000..5da2835 --- /dev/null +++ b/src/chapter10sorting/BubbleSort.java.txt @@ -0,0 +1,35 @@ +class BubbleSort +{ + void bubbleSort(int arr[]) + { + int n = arr.length; + for (int i = 0; i < n-1; i++) + for (int j = 0; j < n-i-1; j++) + if (arr[j] > arr[j+1]) + { + // swap temp and arr[i] + int temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + } + } + + /* Prints the array */ + void printArray(int arr[]) + { + int n = arr.length; + for (int i=0; i