From bb49ab270abc085a251ce61347b01965444846d8 Mon Sep 17 00:00:00 2001 From: ADVAITH U <45172876+ADVAITH18@users.noreply.github.com> Date: Sun, 13 Oct 2019 10:51:21 +0530 Subject: [PATCH] Sorting Algorithms This folder consist of implementation of three sorting algorithms using Java 1.Bubble Sort 2.Selection sort 3.Insertion sort --- Sorting Algorithms/bubble_sort.java | 30 ++++++++++++++++++++ Sorting Algorithms/insertion_sort.java | 39 ++++++++++++++++++++++++++ Sorting Algorithms/selection_sort.java | 30 ++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 Sorting Algorithms/bubble_sort.java create mode 100644 Sorting Algorithms/insertion_sort.java create mode 100644 Sorting Algorithms/selection_sort.java diff --git a/Sorting Algorithms/bubble_sort.java b/Sorting Algorithms/bubble_sort.java new file mode 100644 index 0000000..a982458 --- /dev/null +++ b/Sorting Algorithms/bubble_sort.java @@ -0,0 +1,30 @@ +import java.io.*; +class Bubble +{ + public static void main()throws IOException + { + BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); + int i,j,t,n; + System.out.println("Enter the size of the array"); + n=Integer.parseInt(br.readLine()); + int a[]=new int[n]; + System.out.println("Enter the array elements"); + for(i=0;ia[j+1]) + { + t=a[j]; + a[j]=a[j+1]; + a[j+1]=t; + } + System.out.println("SORTED ARRAY"); + for(i=0;i= 0 && a[j] > key) + { + a[j + 1] = a[j]; + j = j - 1; + } + a[j+1]=key; + + } + //Displaying the array + System.out.println("SORTED ARRAY : "); + for(i=0;ia[j]) + { + t=a[i]; + a[i]=a[j]; + a[j]=t; + } + System.out.println("SORTED ARRAY"); + for(i=0;i