Need a quick solution to this in Java!
import java.io.*;
import java.util.*;
class A{
public static void main(String argv[])throws
Exception{
File file = new
File("a.txt");
Vector<Integer> v = new
Vector<Integer>();
BufferedReader br = new
BufferedReader(new FileReader(file));
String st;
while ((st = br.readLine()) !=
null)
v.add(Integer.parseInt(st));
int[] arr = new
int[v.size()];
for (int i=0;i<v.size();i++)
arr[i]=(int)v.elementAt(i);
System.out.println("\nInteger in a.txt file");
Radix.printArray(arr,arr.length);
Radix.radixSort(arr,arr.length);
System.out.println("\nRadixSort Integer in a.txt file");
Radix.printArray(arr,arr.length);
System.out.println("\n\n");
File file1 = new File("b.txt");
Vector<Integer> v1 = new
Vector<Integer>();
BufferedReader br1 = new
BufferedReader(new FileReader(file1));
String st1;
while ((st1 = br1.readLine()) !=
null)
v1.add(Integer.parseInt(st1));
int[] arr1 = new
int[v1.size()];
for (int i=0;i<v1.size();i++)
arr1[i]=(int)v1.elementAt(i);
System.out.println("\nInteger in b.txt file");
Radix.printArray(arr1,arr1.length);
Radix.radixSort(arr1,arr1.length);
System.out.println("\nRadixSort Integer in b.txt file");
Radix.printArray(arr1,arr1.length);
System.out.println("\n\n");
File file2 = new File("c.txt");
Vector<Integer> v2 = new
Vector<Integer>();
BufferedReader br2 = new
BufferedReader(new FileReader(file2));
String st2;
while ((st2 = br2.readLine()) !=
null)
v2.add(Integer.parseInt(st2));
int[] arr2 = new
int[v2.size()];
for (int i=0;i<v2.size();i++)
arr2[i]=(int)v2.elementAt(i);
System.out.println("\nInteger in c.txt file");
Radix.printArray(arr2,arr2.length);
Radix.radixSort(arr2,arr2.length);
System.out.println("\nRadixSort Integer in c.txt file");
Radix.printArray(arr2,arr2.length);
}
}
class Radix {
static int Max(int arr[], int n)
{
int mx = arr[0];
for (int i = 1; i < n;
i++)
if (arr[i] >
mx)
mx = arr[i];
return mx;
}
static void countSort(int arr[], int n, int exp)
{
int output[] = new int[n];
int i;
int count[] = new int[10];
Arrays.fill(count,0);
for (i = 0; i < n; i++)
count[
(arr[i]/exp)%10 ]++;
for (i = 1; i < 10; i++)
count[i] +=
count[i - 1];
for (i = n - 1; i >= 0;
i--)
{
output[count[
(arr[i]/exp)%10 ] - 1] = arr[i];
count[
(arr[i]/exp)%10 ]--;
}
for (i = 0; i < n; i++)
arr[i] =
output[i];
}
static void radixSort(int arr[], int n)
{
int m = Max(arr, n);
for (int exp = 1; m/exp > 0; exp
*= 10)
countSort(arr,
n, exp);
}
static void printArray(int arr[], int n)
{
for (int i=0; i<n; i++)
System.out.print(arr[i]+" ");
}
}
Need a quick solution to this in Java! OPTION 2: RADIX SORT TESTING Write a version...
Part 1: Extend your sorting framework with two advanced sorting methods of your choice: (Shell Sort OR Radix Sort) AND (Merge Sort OR Quick Sort). If you choose Shell Sort, experiment with different incremental sequences to see how they affect the algorithm's run time efficiency (count the number of comparisons and exchanges). If you choose to implement Radix Sort, answer the following question as well: Can you write a version of Radix Sort to work with real numbers? If yes,...
Write a program in Java that obtains the execution time of selection sort, insertion sort, bubble sort, merge sort, quick sort, and radix sort. Your program should test all sort methods for input sizes of 10000, 20000, 30000, 40000, 50000, and 60000. The selection sort, bubble sort, and radix sort should also be tested for input sizes 100000 and 200000. Your program should create the data that is sorted from randomly generated integers and should output the results in a...
IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us consider the following set of positive integers: 311, 96, 495, 137, 158, 84, 145, 63 We will sort these numbers with three passes. The number of passes is dependent on the number of digits of the largest number - in this case it is 495. In the first pass we will go through and sort the numbers according to the digits in the units...
JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...
C++ SORTING – BUBBLE SORT METHOD Use the below Text File and write code that sorts it based on the users sort method selection. Please provide a separate .cpp file wit hthe code containing the sort method. The sorting method uses the text file below and sorts it accordingly. Seperate the sorting method into an additional C++ file. ********************************* Text File Below is a text file called classes.txt. This text file lists, by course number and section number a series...
Can somebody help me with Java programming? please be brief and explain the process and carefully follow the step by step instruction. Thanks Homework 12.1 - Write a program that generates five random sentences (like mad libs), prints them to a file, then reads in the sentences and prints them to the console. Start by creating four string arrays for nouns, verbs, colors, and places. They should store at least 5 of each type of word. You can have more...
Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1. The input and variable value file are both text files that will be specified in...
Consider a variation of Merge sort called 4-way Merge sort. Instead of splitting the array into two parts like Merge sort, 4-way Merge sort splits the array into four parts. 4-way Merge divides the input array into fourths, calls itself for each fourth and then merges the four sorted fourths. a)Implement 4-way Merge sort from Problem 4 to sort an array/vector of integers and name it merge4. Implement the algorithm in the same language you used for the sorting algorithms...
Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....