Base sort (algorithm) --- find a tree to hang

xiaoxiao2021-03-06  53

This algorithm is sorted for two digits, namely: 3, 5, 11, 14, 42, 23, 21 .... (Other digits can be extended by themselves, where quequei is queue). It is a very interesting algorithm.

PRIVATE FINAL INT Ones = 1; //

Public void basecompositor (int [] redata) throws quequeexception {

Quequei [] q = new quequei [10];

For (int i = 0; i <10; i )

Q [i] = new quequei (10);

Distribute (Redata, Q, Ones);

Collect (Redata, Q);

Print (Redata);

System.out.println ("=======================");

Distribute (Redata, Q, 2); // Ten

Collect (Redata, Q);

Print (Redata);

}

// distribute data to queque

Public void distribute (int [] redata, quequei [] q, int kind) throws quequeexception {

INT i = 0;

IF (Kind == Ones) {

While (i

q [redata [i]% 10] .insert (redata [i]);

i ;

}

} else {

While (i

Q [redata [i] / 10] .insert (Redata [i]);

i ;

}

}

}

// Collect Data in Queque to Array

Public void collect (int [] redata, quequei [] q) throws quequeexception {

INT TEMP = 0;

For (int i = 0; i <10; i ) {

While (! q [i] .Isempty ()) {

Redata [Temp ] = Q [i] .delete ();

}

}

}

// Print Data in Array

Public void print (int [] redata) {

For (int i = 0; i

System.out.print (Redta [i] ");

SYSTEM.OUT.PRINTLN ();

}

转载请注明原文地址:https://www.9cbs.com/read-84009.html

New Post(0)