tag:blogger.com,1999:blog-5327046495053561503.post8950654198813115787..comments2023-07-25T13:09:12.340+05:30Comments on Tech Tutorials: Radix Sort Program in JavaAnshudeephttp://www.blogger.com/profile/05912349277663872766noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5327046495053561503.post-15468490918494192902019-11-27T10:15:15.852+05:302019-11-27T10:15:15.852+05:30Just have a look at your getMaxElement() method, h...Just have a look at your getMaxElement() method, how are you calculating max element there? Shouldn't there be a if condition to check if next element is greater than the current?Bucket Sort Program in Javahttps://netjs.blogspot.com/2019/01/bucket-sort-program-in-java.htmlnoreply@blogger.comtag:blogger.com,1999:blog-5327046495053561503.post-53968573356763541182019-11-26T07:38:24.149+05:302019-11-26T07:38:24.149+05:30Hi I tried to excute same program, but final resul...Hi I tried to excute same program, but final result is not sorted properly. Wanted to clarify whether Radix Sort doesnt give consistent results for same set of input.<br /><br />Code :<br />package Trees.src.com.cracking.Sorting;<br /><br />import java.util.Arrays;<br /><br />public class RadixSort {<br /><br /> public static void main(String[] args){<br /> int[] array = {80, 406, 21, 655, 55, 4, 8, 91, 87, 6};<br /> int max = getMaxElement(array);<br /> System.out.println(max);<br /> int position = 1;<br /> while(max/position > 0)<br /> {countingSort(array,position);position = position * 10;}<br /> }<br /><br /> public static int getMaxElement(int arr[]){<br /> int max = arr[0];<br /> for(int i=1;i max)<br /> max = arr[i];<br /> return max;<br /> }<br /><br /> //counting sort but sort at each position<br /> public static void countingSort(int[] arr,int position){<br /> int[] count = new int[arr.length];<br /> int[] output = new int[arr.length];<br /><br /> for(int i=0;i<arr.length;i++)<br /> count[(arr[i]/position)%10]++;<br /><br /> for(int i=1;i<count.length;i++)<br /> count[i] = count[i] + count[i-1];<br /><br /> for(int i=0;i<arr.length;i++)<br /> {<br /> output[count[(arr[i]/position)%10] - 1] = arr[i];count[(arr[i]/position)%10]--;<br /> }<br /><br /> for(int i=0;i<arr.length;i++)<br /> arr[i] = output[i];<br /><br /> System.out.println(Arrays.toString(arr));<br /> }<br />}<br />Amit Khttps://www.blogger.com/profile/00580222474289960300noreply@blogger.com