
Concept explainers
Programming Radix Sort
You will implement Radix Sort on arrays of base 10 integers between 0 and 2,147,483,647
(Integer.MAX_VALUE). You will implement RadixSort in a new way using an array of Queues
to sort the values by digit. Your
simple implementation of a Queue (Queue.java) that inserts and removes elements in
constant time.
This is method signature Class to use Programming Radix Sort:
package sorting;
import java.util.Arrays;
public class RadixSorter{
//returns the max value in the array
//used to provide the k to counting sort
private static int getMax(int[] arr) {
int max = Integer.MIN_VALUE;
for(int i: arr) {
if(i>max)
max = i;
}
return max;
}
public static void radixSort(int[] arr) {
//Get the maximum to know how many digits I have
int max = getMax(arr);
}
}
And this is queue Class:
package sorting;
import java.util.NoSuchElementException;
public class Queue {
private static class Node {
int data;
Node next;
public Node(int data) {
this.data = data;
next = null;
}
}
private Node front;
private Node back;
private int size;
public void enqueue(int i) {
Node toInsert = new Node(i);
if(size==0) {
front = toInsert;
back = toInsert;
size++;
}
else {
back.next = toInsert;
back = back.next;
size++;
}
}
public int dequeue() {
if(size==0) {
throw new NoSuchElementException("Queue is Empty");
}
int frontData = front.data;
if(size==1) {
front = null;
back = null;
}
else {
front = front.next;
}
size--;
return frontData;
}
public int peek() {
if(size==0) {
throw new NoSuchElementException("Queue is Empty");
}
return front.data;
}
public boolean isEmpty() {
return size==0;
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 1 images

The updated code doesn't handle the arary with negative numbers. Can you help update the code to handle negative numbers?
The updated code doesn't handle the arary with negative numbers. Can you help update the code to handle negative numbers?
- In java how do you: Delete the lowest/smallest item from the Circular Linked List (provided the list is sorted in ascending order) Reverse a Stack S, using a Queue Q Add the top 2 elements of a Stack S. Return the addition and push the data back in the stack S. How to reverse a Queue using a Stack? How to reverse a Queue using an array?arrow_forwardJAVA please Given main() in the ShoppingList class, define an insertAtEnd() method in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node. Ex. if the input is: 4 Kale Lettuce Carrots Peanuts where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added at the end of the list. The output is: Kale Lettuce Carrots Peanuts Code provided in the assignment ItemNode.java:arrow_forwardExecute a program that will split a circularly linked list P with n nodes intotwo circularly linked lists P1, P2 with the first n/2 and the last n – n/2 nodes ofthe list P in them.arrow_forward
- Java's LinkedList provides a method listlterator(int index) returning a Listlterator for a list. Declare a variable of LinkedList of integer numbers and write a fragment of Java code to compute and print the sum of the numbers on the list. Do not write code to insert elements to the list and assume that the list already has elements on it. You must only use an iterator obtained from the list (you can not use the get(int index) method) .arrow_forwardcan I have the solution for this question in Java coding please? Write an algorithm for the following to swap two adjacent elements by adjusting only the links (and not the data) using: Singly-linked lists. Doubly linked lists.arrow_forwardprovided code: import java.util.Comparator;import java.util.List;import java.util.LinkedList;import java.util.Queue; /** * Your implementation of various divide & conquer sorting algorithms. */ public class Sorting { /** * Implement merge sort. * * It should be: * out-of-place * stable * not adaptive * * Have a worst case running time of: O(n log n) * And a best case running time of: O(n log n) * * You can create more arrays to run merge sort, but at the end, everything * should be merged back into the original T[] which was passed in. * * When splitting the array, if there is an odd number of elements, put the * extra data on the right side. * * Hint: You may need to create a helper method that merges two arrays * back into the original T[] array. If two data are equal when merging, * think about which subarray you should pull from first. * * You may assume that the passed in array and…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





