From a3536b9ebe68b4b7ab78ac9960e5c2a50d84acc7 Mon Sep 17 00:00:00 2001 From: GauravWalia19 Date: Thu, 18 Apr 2019 13:16:45 +0530 Subject: [PATCH] added array rotation 3 approaches --- .../ARRAYS/MISC/ArrayRotation1.java | 42 +++++++ .../ARRAYS/MISC/ArrayRotation2.java | 35 ++++++ .../ARRAYS/MISC/jugglingAlgo.java | 44 +++++++ Java/README.md | 4 + datastructures.md | 114 +++++++----------- 5 files changed, 171 insertions(+), 68 deletions(-) create mode 100644 Java/Data-Structures/ARRAYS/MISC/ArrayRotation1.java create mode 100644 Java/Data-Structures/ARRAYS/MISC/ArrayRotation2.java create mode 100644 Java/Data-Structures/ARRAYS/MISC/jugglingAlgo.java diff --git a/Java/Data-Structures/ARRAYS/MISC/ArrayRotation1.java b/Java/Data-Structures/ARRAYS/MISC/ArrayRotation1.java new file mode 100644 index 0000000..1782132 --- /dev/null +++ b/Java/Data-Structures/ARRAYS/MISC/ArrayRotation1.java @@ -0,0 +1,42 @@ +/* + * ARRAY ROTATION USING TEMP ARRAY + * LEFT ROTATE TO 2 + */ +import java.util.*; +public class ArrayRotation1 +{ + public static void main(String[] args) + { + Scanner in = new Scanner(System.in); + int[] arr = {1,2,3,4,5,6,7}; + int shift=2; + + rotate(arr,shift,arr.length); + + in.close(); + } + public static void rotate(int[] arr,int d,int n) + { + int[] temp = new int[d]; + //copy arr 2 elements to temp + for(int i=0;i