0 Replies - 1101 Views - Last Post: 19 April 2011 - 07:37 PM

#1 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1741
  • View blog
  • Posts: 5,896
  • Joined: 03-August 09

Radix sort in D

Posted 19 April 2011 - 07:37 PM

Description: simply pass your array to the function and it will be sorteda fast implementation of a Radix sort for unsigned integers implemented in D.
import std.stdio;

void RadixSort(ref uint[] SL) {
	scope uint[][256] Buckets;
	scope uint B0Size=0;
	scope uint i=0;
	scope uint size = SL.length;
	scope uint* T;
	for(;B0Size!=size;++i) {
		foreach(x; SL) {
			Buckets[(x>>(i<<3))&255] ~= x;
		}
		B0Size = (*Buckets).length;
		T = cast(uint*)SL;
		foreach(ref B; Buckets) {
			foreach(B2; B) {
				*T++ = B2;
			}
			B.clear();
		}
	}
}

void main() {
   uint[] SL = [10,9,8,7,6,5,4,3,2,1,0];
   RadixSort(SL);
   writeln(SL);
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1