Question: can any one please edit this code getting lot of errors: q) Implement the radix sort, as given in Segment 9.21 of Chapter 9, by

can any one please edit this code getting lot of errors:

q) Implement the radix sort, as given in Segment 9.21 of Chapter 9, by using a queue for each bucket.

Pseudocode of radix sort

9.21: Our previous description of radix sort assumed that the integers to be sorted each contain the same number of digits. Actually, this requirement is unnecessary as long as you get 0 when you ask for a digit that does not exist. For example, if you ask for the hundreds digit of a two-digit integer, you should get 0. The following algorithm describes a radix sort of an array of positive decimal integers. We number the digits in each integer from the right beginning at zero. Thus, the units digit is digit 0, the tens digit is digit 1, and so on.

Algorithm radixSort(a, first, last, maxDigits) // Sorts the array of positive decimal integers a[first..last] into ascending order; // maxDigits is the number of digits in the longest integer. for (i = 0 to maxDigits - 1) { Clear bucket[0], bucket[1], . . . , bucket[9] for (index = first to last) { digit = digit i of a[index] Place a[index] at end of bucket[digit] } Place contents of bucket[0], bucket[1], . . . , bucket[9] into the array a } This algorithm uses an array of buckets. The nature of a bucket is unspecified, but after you read Chapter 10, you will see that a bucket can be an instance of the ADT queue.

class LinkedQueueimplements QueueInterfaces { private Node startingNode; public LinkedQueue() { startingNode=null; endingNode=null; } public void enqueue(T newEntry) { Node newNode=new Node(newEntry, null); if(isEmpty()) startingNode=newNode; else endingNode.setNextNode(newNode); endingNode=newNode; } public T getFront() { T front=null; if(!isEmpty()) { fromt=startingNode.getData(); startingNode=startingNode.getNextNode(); if(startingNode==null) endingNode=null; } return front; } public boolean isEmpty() { return(startingNode==null)&&(endingNode==null); } public void clear() { private T newdata; private Node nextNode private Node(T dataPortion) { newdata=dataPortion; nextNode=null; } private Node(T dataPortion,Node linkPortion) { newdata=dataPortion; nextNode=linkPortion; } privata T getData() { return newdata; } private void setData(T newData) { newdata=newData; } private Node getNextNode() { return nextNode; } private void setNextNode(Node nextNode) { this.nextNode=nextNode; } } } interface QueueInterface { public void enqueue(T newEntry); public T dequeue(); public T getFront(); public boolean isEmpty(); public void clear(); } public class RadixSort { public static final int RADIX=10; public static void radix(int[]a, int initital, int last, int maxDigits) { //@SuppressWarnings should be unchecked

@SuppressWarnings("unchecked") QueueInterface[]buckets=new LinkedQueue[RADIX]; int buc,i,index; for(buc=0;buc

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!