Olha ai em
Por: ph_infinit • 4/12/2015 • Monografia • 1.495 Palavras (6 Páginas) • 230 Visualizações
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package radix;
/**
*
* @author Morena
*/
public class Radix {
public static final int max = 1900;
public static final int infinity = 9999;
public static int[] toSortArray = new int [max];
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int[][] matrix = new int [max][max];
int[] bucketCounter = new int[max];
for (int i = 0; i < max; i++) {
bucketCounter[i]= 0;
toSortArray[i] = (int) (Math.random()*1900);
for (int j = 0; j < max; j++) {
matrix [i][j]=infinity;
}
}
System.out.println("the array to be sorted is: ");
for (int i = 0; i < max; i++) {
System.out.print(" | "+toSortArray[i]);
}
System.out.println(" ");
int maxNum=0;
for (int i = 0; i < max; i++) {
if(maxNum<toSortArray[i]){
maxNum = toSortArray[i];
}
}
System.out.println("The largest number in the array is "+maxNum);
int length = 0;
while(maxNum!=0){
length++;
maxNum = maxNum/10;
}
System.out.println("The length of the largest number is "+length);
int placementIndex = 0;
int placementCounter =1;
int arrayHolder;
while(length!=0){
//find the last, second last, so on and do forth
for (int i = 0; i < max; i++) {
arrayHolder= toSortArray[i];
for (int j = placementCounter; j !=0; j--) {
placementIndex = arrayHolder%10;
arrayHolder = arrayHolder/10;
}
matrix[placementIndex][bucketCounter[placementIndex]]=toSortArray[i];
bucketCounter[placementIndex]++;
}
System.out.println("");
for (int i = 0; i < max; i++) {
System.out.println("");
...