I am yet to see someone who truly implements this question with the generic Queue.java file provided.
Question:
I am yet to see someone who truly implements this question with the generic Queue.java file provided. Many implementations I have seen use the library in java. I want to be sure that I am not doing the wrong thing. I can implement using the java library but not this one. Please see the question and the queue file that I must use. Please don't use the library that comes with java. Implement the Radix Sortalgorithm using queues (each bucket is a queue) we discussed in class,Queue.java is given. Call the programRadixSortYourName.java. The program prompts the user to enter the number of input values, then reads that many positive integer values and store them in an array of type integer (call itinputs). Again, the program applies radix sort algorithm we discussed to the values stored in arrayinputs, and then prints out the content of the array before and after being sorted. (Assume there is no limitation of the number of digits of each integer. For example, your program must be able to handle any possible integer numbers such as 492195 or 9817352)
How many integer numbers do you have?:6 // <- user input
Enter6 integer numbers:214 3466 8 30 542 46 // <- user input
------------------------------------------------------
Inputs array before sorting (radix): 214, 3466, 8, 30, 542, 46
Inputs array after sorting (radix): 8, 30, 46, 214, 542, 3466
FYI, Radix sort requires digit extraction. To do so, you'd better implement a separate method in classRadixSort (call itextractDigit(...)) function. You also need to implement another method to do digit count in a number.
// This class defines a Queue
public class Queue { public Node head, tail; //constructor method to create a list of object with head, tail, and size. public Queue() { head = null; tail = null; } //method add node to end of list public void addLastNode(E data) { if (tail == null) head = tail = new Node(data); //empty list else { tail.next = new Node(data); //link new node as last node tail = tail.next; //make tail pointer points to last node } }
// Method for enqueue (same as addlast for linked list) public void enqueue(E data) { int size= Size(); Node NewNode; NewNode= new Node(data); if (tail==null) // case for if our Queue is empty head=tail=new Node(data); else { tail.next=new Node(data); tail=tail.next; } size++; }
// Method for dequeue (same as removefirst for linked list) public void dequeue() { int size= Size(); Node temp; if (size==0) { System.out.println("ERROR QUEUE IS EMPTY!!!!"); } else if (size==1) // if our stack only has one element { temp= head; head=tail=null; size=0; } else{ Node C; // Create new node C= head; // Link Node C point to head head=head.next; // Make the head point to the 2nd node } }
// Method for size, counts and gives us the number of elements (nodes) in our Queue public int size() { Node Current3; int size=0; //Create int variable to store the number of nodes Current3= head; //Set current node to the head while (Current3 != null) //While the Current node doesn't equal null move forward node by node counting each node as you pass them by { size= size+1; Current3= Current3.next; } return size; //Return the number of elements (leave method useful for when we want to remove/add at an index >= Count) }
// Method for front, looks at the 1st element of the Queue and returns that element public E front() { E X; if (isEmpty()==false) X=(E)head.data; else X=null; return X; //return the element that is at the head }
// Method for isEmpty(), checks to see if the list is empty public boolean isEmpty() { int size= Size(); if (size==0) return true; else return false; }
//============end of methods=============================
//method to print out the Queue public void printQueue() { Node temp; temp = head; while (temp != null) { System.out.print(temp.data + " "); temp = temp.next; } } //class to create nodes as objects private class Node { private E data; //data field private Node next; //link field public Node(E item) //constructor method { data = item; next = null; } } }
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill