From 6d3096eed9f5da50fa8c724de01ec862f2f5275e Mon Sep 17 00:00:00 2001 From: pasanjayawickrama Date: Sun, 13 Oct 2019 17:29:53 +0530 Subject: [PATCH] Added Bubble sort --- Sorting Algorithms/BubbleSort.java | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Sorting Algorithms/BubbleSort.java diff --git a/Sorting Algorithms/BubbleSort.java b/Sorting Algorithms/BubbleSort.java new file mode 100644 index 0000000..c890c16 --- /dev/null +++ b/Sorting Algorithms/BubbleSort.java @@ -0,0 +1,33 @@ +public class BubbleSort { + public static void BubbleSort( int [ ] no ) + { + int j; + boolean flag = true; + int temp; + + while ( flag ) + { + flag= false; + for( j=0; j < no.length -1; j++ ) + { + if ( no[ j ] < no[j+1] ) + { + temp = no[ j ]; + no[ j ] = no[ j+1 ]; + no[ j+1 ] = temp; + flag = true; + } + } + } + + for(int p = 0 ;p