From 01bef5899c9f6256352c97276c70a6f1d203bd4b Mon Sep 17 00:00:00 2001 From: Abhishek Kapratwar Date: Sat, 19 Oct 2019 10:29:15 +0530 Subject: [PATCH] added sub Array in java --- Algorithms/Bubblesort/Kotlin/BubbleSort.kt | 27 --------------- Algorithms/Bubblesort/kotlin/BubbleSort.kt | 18 ---------- .../Recursion/FindSubArray/FindSubArray.java | 34 +++++++++++++++++++ 3 files changed, 34 insertions(+), 45 deletions(-) delete mode 100644 Algorithms/Bubblesort/Kotlin/BubbleSort.kt delete mode 100644 Algorithms/Bubblesort/kotlin/BubbleSort.kt create mode 100644 Algorithms/Recursion/FindSubArray/FindSubArray.java diff --git a/Algorithms/Bubblesort/Kotlin/BubbleSort.kt b/Algorithms/Bubblesort/Kotlin/BubbleSort.kt deleted file mode 100644 index d8537e00..00000000 --- a/Algorithms/Bubblesort/Kotlin/BubbleSort.kt +++ /dev/null @@ -1,27 +0,0 @@ -import java.util.* -fun bubbleSort(arr:IntArray){ - for(i in 0 until arr.size-1){ - for(j in 0 until arr.size-i-1){ - if(arr[j]>arr[j+1]){ - var temp = arr[j] - arr[j] = arr[j+1] - arr[j+1] = temp - } - } - } -} -fun main(args:Array) { - var scanner = Scanner(System.`in`) - print("enter the size to be sorted ") - var sizeOfList = scanner.nextInt() - val array = IntArray(sizeOfList) - print("start entering values to be sorted ") - for (i in 0 until sizeOfList) { - array[i] = scanner.nextInt(); - } - bubbleSort(array) - for (i in 0 until sizeOfList){ - print(array[i]) - print(" ") - } -} \ No newline at end of file diff --git a/Algorithms/Bubblesort/kotlin/BubbleSort.kt b/Algorithms/Bubblesort/kotlin/BubbleSort.kt deleted file mode 100644 index 12344e45..00000000 --- a/Algorithms/Bubblesort/kotlin/BubbleSort.kt +++ /dev/null @@ -1,18 +0,0 @@ -class DummyBubbleSort { - - private fun sortArray(numbers: Array) { - for (currentPosition in 0 until (numbers.size - 1)) { - if (numbers[currentPosition] > numbers[currentPosition + 1]) { - val tmp = numbers[currentPosition] - numbers[currentPosition] = numbers[currentPosition + 1] - numbers[currentPosition + 1] = tmp - } - } - } - - fun main(args: Array) { - val numbers = arrayOf(69, 42, 666, 1, 969, 23, 6, 2, 0, 87) - sortArray(numbers) - numbers.forEach(::print) - } -} diff --git a/Algorithms/Recursion/FindSubArray/FindSubArray.java b/Algorithms/Recursion/FindSubArray/FindSubArray.java new file mode 100644 index 00000000..eeef2492 --- /dev/null +++ b/Algorithms/Recursion/FindSubArray/FindSubArray.java @@ -0,0 +1,34 @@ +import java.util.*; +class FindSubArray +{ + static void subArray(int []arr, int start, int end) + { + if (end == arr.length) + return; + else if (start > end) + subArray(arr, 0, end + 1); + else + { + System.out.print("("); + for (int i = start; i < end; i++){ + System.out.print(arr[i]+", "); + } + System.out.println(arr[end]+")"); + subArray(arr, start + 1, end); + } + return; + } + public static void main(String args[]) + { + int n; + Scanner scanner = new Scanner(System.in); + System.out.println("Enter size of array: "); + n = scanner.nextInt(); + int arr[] = new int[n]; + System.out.println("Enter Elements of Array: "); + for(int i=0; i