Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My task is to Implement a radix sort function for integers that sorts with queue

ID: 3623511 • Letter: M

Question

My task is to Implement a radix sort function for integers that sorts with queues.The function should take one queue as an argument and on return that queue should contain the same values in ascending order. The implementation should make multiple passes over the input values, one pass for each digit in the input values. You may assume that the values are between 0 and 999.

 

Hope someone can help me. I understand Radix sort but i am having problems with putting my knowledge about radix sort in code. Please try to leave comments in code. Want to understand this sorting algorithm. Would be perfect to get also main function that use the sort on few numbers. 

 


My Queue is :

 

class IntQueue{

 

static class Hlekkur

 

  { int tala; Hlekkur naest; }

 

Hlekkur fyrsti;

 

Hlekkur sidasti;

 

int n;

 

 

 

public IntQueue()

 

{ fyrsti = sidasti = null; }

 

// show first number in queue.

 

 

 

public int first()

 

{ return fyrsti.tala; }

 

 

 

public int get()

 

{ int res = fyrsti.tala; n--;

 

if( fyrsti == sidasti ) fyrsti = sidasti = null;

 

else fyrsti = fyrsti.naest;

 

return res; }

 

 

 

public void put( int i )

 

{ Hlekkur nyr = new Hlekkur(); n++;

 

nyr.tala = i;

 

if( sidasti==null ) fyrsti = sidasti = nyr;

 

else {

 

sidasti.naest = nyr; sidasti = nyr; }

 

}

 

 

 

public int count()

 

{ return n; }

 

}

Explanation / Answer

Dear.. import java.util.*; class Radix { static int[] radixSort(int[] arr) { class Bucket { private List list = new LinkedList(); int[] sorted; public void add(int i) { list.add(i); sorted = null; } public int[] getSortedArray() { if(sorted == null) { sorted = new int[list.size()]; int i = 0; for(Integer val : list) { sorted[i++] = val.intValue(); } Arrays.sort(sorted); } return sorted; } } int maxLen = 0; for(int i : arr) { if(i < 0) throw new IllegalArgumentException("I don't deal with negative numbers"); int len = numKeys(i); if(len > maxLen) maxLen = len; } Bucket[] buckets = new Bucket[maxLen]; for(int i = 0; i