diff --git a/Java/Data-Structures/ARRAYS/MISC/spiralOrder.java b/Java/Data-Structures/ARRAYS/MISC/spiralOrder.java new file mode 100644 index 0000000..09cb6cc --- /dev/null +++ b/Java/Data-Structures/ARRAYS/MISC/spiralOrder.java @@ -0,0 +1,85 @@ +import java.util.*; +abstract class spiralOrder +{ + /** + * SAMPLE TEST CASE + * 3 3 + * 1 2 3 + * 4 5 6 + * 7 8 9 + * + * OUTPUT + * 1 + * 2 + * 3 + * 6 + * 9 + * 8 + * 7 + * 4 + * 5 + **/ + public static void main(String[] args) + { + Scanner in = new Scanner(System.in); + int n = in.nextInt(); + int m = in.nextInt(); + int[][] arr = new int[n][m]; + for(int i=0;i r + for(int i=sc;i=sc;i--) + { + System.out.println(arr[er-1][i]); + } + er--; + } + + // ^ + // | + if(sc=sr;i--) + { + System.out.println(arr[i][sc]); + } + sc++; + } + } + } +} \ No newline at end of file diff --git a/Java/README.md b/Java/README.md index b1f1df0..31b849e 100644 --- a/Java/README.md +++ b/Java/README.md @@ -16,6 +16,7 @@ * [ARRAYS CLASS](Data-Structures/ARRAYS/INBUILT/arrays.java) * MISC * JAGGED ARRAY + * [SPIRAL ORDER MATRIX](Data-Structures/ARRAYS/MISC/spiralOrder.java) #### STRING diff --git a/datastructures.md b/datastructures.md index 41269ac..f967489 100644 --- a/datastructures.md +++ b/datastructures.md @@ -83,6 +83,13 @@ Indexer for Data Structures Lover * [C](C/Data-Structures/ARRAYS/MISC/jaggedarray.c) * complexity +#### SPIRAL ORDER MATRIX + +* blog/docs +* implementation + * [JAVA](Java/Data-Structures/ARRAYS/MISC/spiralOrder.java) +* complexity + ## :octocat: STRING * blog