Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- /**
- *
- * @author urksiful
- */
- public class RadixResp{
- static int comp=0, mov=0;
- public static void main(String[] args) {
- ArrayList<Integer> lista = new ArrayList<Integer>();
- for (int i = 0; i < 100; i++) {
- lista.add((int) (Math.random() * 998) + 1);
- System.out.print(lista.get(i)+" ");
- }
- System.out.println("");
- int[][] np = new int[lista.size()][2];
- int[] q = new int[0x100];
- int i, j, k, l, f = 0;
- for (k = 0; k < 4; k++) {
- for (i = 0; i < (np.length - 1); i++) {
- np[i][1] = i + 1;
- }
- np[i][1] = -1;
- for (i = 0; i < q.length; i++) {
- q[i] = -1;
- }
- for (f = i = 0; i < lista.size(); i++) {
- j = ((0xFF << (k << 3)) & lista.get(i)) >> (k << 3);
- if (q[j] == -1) {
- l = q[j] = f;
- } else {
- l = q[j];
- while (np[l][1] != -1) {
- l = np[l][1];
- }
- np[l][1] = f;
- l = np[l][1];
- }
- f = np[f][1];
- np[l][0] = lista.get(i);
- np[l][1] = -1;
- }
- comp++;
- for (l = q[i = j = 0]; i < 0x100; i++) {
- for (l = q[i]; l != -1; l = np[l][1]) {
- lista.set(j++, np[l][0]);
- mov++;
- }
- }
- }
- for(int y=0; y<100; y++){
- System.out.print(lista.get(y)+" ");
- }
- System.out.println("\nMovimientos: "+mov);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement