Radixsort

Radixsort - import java.io.*; /* A Node class that stores...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 import java.io.* /** A Node class that stores String data. **/ class Node { String data Node next Node (String data, Node next) { this.data = data this.next = next } public String toString() { return data } } /** * This class sorts a given list of strings which represent numbers in * the given radix system. For instance, radix=10 means decimal numbers * radix=16 means hexadecimal numbers. */ public class Radixsort { int radix Node[] buckets Node masterListRear int maxDigits int n // read input and initialize buckets public void init(BufferedReader in) throws IOException { // first line is radix radix = Integer.parseInt(in.readLine()) // one value per line masterListRear = null String str = in.readLine() n = 0 while (str != null) { n++ Node temp = new Node(str, null) temp.next = temp masterListRear = append(masterListRear, temp) str = in.readLine() } buckets = new Node[radix] } // main sorting method public void sort() {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 Page 2 /* COMPLETE THIS METHOD */ Node ptr = masterListRear
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Radixsort - import java.io.*; /* A Node class that stores...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online