From 3bbcfaf573238bf6d7b82866c56379255e46edfb Mon Sep 17 00:00:00 2001 From: Atish Jain Date: Mon, 14 Jun 2021 11:21:16 +0530 Subject: [PATCH 1/4] Added Radix Sort --- .../01. Arrays/03. Sorting/.classpath | 10 +++ .../01. Arrays/03. Sorting/.project | 17 ++++ .../03. Sorting/06. RadixSort/RadixSort.java | 86 +++++++++++++++++++ .../01. Arrays/03. Sorting/bin/.gitignore | 1 + 4 files changed, 114 insertions(+) create mode 100644 02. Algorithms/01. Arrays/03. Sorting/.classpath create mode 100644 02. Algorithms/01. Arrays/03. Sorting/.project create mode 100644 02. Algorithms/01. Arrays/03. Sorting/06. RadixSort/RadixSort.java create mode 100644 02. Algorithms/01. Arrays/03. Sorting/bin/.gitignore diff --git a/02. Algorithms/01. Arrays/03. Sorting/.classpath b/02. Algorithms/01. Arrays/03. Sorting/.classpath new file mode 100644 index 0000000..241d4b7 --- /dev/null +++ b/02. Algorithms/01. Arrays/03. Sorting/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/02. Algorithms/01. Arrays/03. Sorting/.project b/02. Algorithms/01. Arrays/03. Sorting/.project new file mode 100644 index 0000000..1a6b40c --- /dev/null +++ b/02. Algorithms/01. Arrays/03. Sorting/.project @@ -0,0 +1,17 @@ + + + 03. Sorting + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/02. Algorithms/01. Arrays/03. Sorting/06. RadixSort/RadixSort.java b/02. Algorithms/01. Arrays/03. Sorting/06. RadixSort/RadixSort.java new file mode 100644 index 0000000..7582ec0 --- /dev/null +++ b/02. Algorithms/01. Arrays/03. Sorting/06. RadixSort/RadixSort.java @@ -0,0 +1,86 @@ + +import java.util.ArrayList; + +public class RadixSort { + + public static void sort(int arr[],int div) //function to store based on their digit + { + ArrayList> array = new ArrayList>(); // array contains list which has elemnets according to their digit + for(int i=0;i<10;i++) //size of array taken as 10 i.e. 0 to 9 + { + ArrayList tempList = new ArrayList(); + array.add(tempList); + } + for(int i=0;i tempList =new ArrayList(); + tempList.add(arr[i]); + array.add((arr[i]/div)%10, tempList); + } + else // if size of list at desired index of array is not zero then remove old list put new list at that index + { + ArrayList tempList =new ArrayList(); + tempList = array.get((arr[i]/div)%10); + array.remove((arr[i]/div)%10); + tempList.add(arr[i]); + array.add((arr[i]/div)%10, tempList); + } + } + + int k=0; //put sorted values in the original array + for(int i=0;i0;div=div*10) //loop runs as equal number of times as there are total number of digits in maximum integer + { + sort(arr,div); + } + } + + + public static int max(int arr[]) //maximum number is found to calculate how many times loop will run + { + int max = arr[0]; + for(int i=1;imax) + { + max=arr[i]; + } + } + return max; + } + + public static void print(int arr[]) //function to print final sorted array + { + for(int i=0;i Date: Mon, 14 Jun 2021 11:23:24 +0530 Subject: [PATCH 2/4] Delete 02. Algorithms/01. Arrays/03. Sorting/bin directory --- 02. Algorithms/01. Arrays/03. Sorting/bin/.gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 02. Algorithms/01. Arrays/03. Sorting/bin/.gitignore diff --git a/02. Algorithms/01. Arrays/03. Sorting/bin/.gitignore b/02. Algorithms/01. Arrays/03. Sorting/bin/.gitignore deleted file mode 100644 index 18757d3..0000000 --- a/02. Algorithms/01. Arrays/03. Sorting/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/RadixSort.class From e1d1dd68fa3b05fe8a20cb6d08a5f3139b682898 Mon Sep 17 00:00:00 2001 From: Atish-Jain <83014070+Atish-Jain@users.noreply.github.com> Date: Mon, 14 Jun 2021 11:23:44 +0530 Subject: [PATCH 3/4] Delete .classpath --- 02. Algorithms/01. Arrays/03. Sorting/.classpath | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 02. Algorithms/01. Arrays/03. Sorting/.classpath diff --git a/02. Algorithms/01. Arrays/03. Sorting/.classpath b/02. Algorithms/01. Arrays/03. Sorting/.classpath deleted file mode 100644 index 241d4b7..0000000 --- a/02. Algorithms/01. Arrays/03. Sorting/.classpath +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - From f187f904c609f94fe3a3c0f12fff7fafb4c5ba4b Mon Sep 17 00:00:00 2001 From: Atish-Jain <83014070+Atish-Jain@users.noreply.github.com> Date: Mon, 14 Jun 2021 11:24:00 +0530 Subject: [PATCH 4/4] Delete .project --- 02. Algorithms/01. Arrays/03. Sorting/.project | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 02. Algorithms/01. Arrays/03. Sorting/.project diff --git a/02. Algorithms/01. Arrays/03. Sorting/.project b/02. Algorithms/01. Arrays/03. Sorting/.project deleted file mode 100644 index 1a6b40c..0000000 --- a/02. Algorithms/01. Arrays/03. Sorting/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - 03. Sorting - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - -