diff --git a/Sorting algorithms/Mayur/BubbleSort b/Sorting algorithms/Mayur/BubbleSort new file mode 100644 index 0000000..868742f --- /dev/null +++ b/Sorting algorithms/Mayur/BubbleSort @@ -0,0 +1,34 @@ +import java.util.Scanner; +public class Bubble_sort { + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner s = new Scanner(System.in); + System.out.println("Enter size of array: "); + int n=s.nextInt(); + int[] arr=new int[5]; + System.out.println("Enter elements of array: "); + for(int i=0;iarr[j+1]) + { + temp=arr[j]; + arr[j]=arr[j+1]; + arr[j+1]=temp; + } + } + } + } + +} diff --git a/Sorting algorithms/Mayur/MergeSort.java b/Sorting algorithms/Mayur/MergeSort.java new file mode 100644 index 0000000..aa51d1d --- /dev/null +++ b/Sorting algorithms/Mayur/MergeSort.java @@ -0,0 +1,59 @@ +public class MergeSort { + public static void main(String[] args) { + // TODO Auto-generated method stub + int[] arr = {8,7,10,6,9,3}; + int[] ans=MergeSort(arr,0,arr.length-1); + for(int i=0;istart) //Left SubArray contains more than 1 element. + quicksort(arr,start,indx-1); + if(indx+1=arr[pivot] && right!=pivot) + right--; + if(right==pivot) + return pivot; + temp = arr[pivot]; + arr[pivot] = arr[right]; + arr[right] = temp; + pivot = right; + while(arr[left]<=arr[pivot] && left!=pivot) + left++; + if(left==pivot) + return pivot; + temp = arr[pivot]; + arr[pivot] = arr[left]; + arr[left] = temp; + pivot = left; + } + } + } diff --git a/Sorting algorithms/Mayur/SelectionSort.java b/Sorting algorithms/Mayur/SelectionSort.java new file mode 100644 index 0000000..849d129 --- /dev/null +++ b/Sorting algorithms/Mayur/SelectionSort.java @@ -0,0 +1,34 @@ +import java.util.Scanner; + public class SelectionSort { + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner s = new Scanner(System.in); + System.out.println("Enter Size of array: "); + int n=s.nextInt(); + int[] arr=new int[n]; + System.out.println("Enter elements of array: "); + for(int i=0;iarr[j]) + min=j; + } + temp=arr[i]; + arr[i]=arr[min]; + arr[min]=temp; + } + } + +}