Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
527 B
2
Indexable
Never
void radixSortTopDown(int a[], int left, int right, int bitpos = 16) {
	if (left >= right || bitpos < 0) return;
	const int radix = 2;
	queue<long> queues[radix];
	for (int i = left; i <= right; i++)
		queues[(a[i] >> bitpos) % radix].push(a[i]);
	// Ket hop
	int mid = queues[0].size();
	for (int i = 0, k = left; i < radix; i++)
		while (!queues[i].empty()) {
			a[k++] = queues[i].front();
			queues[i].pop();
		}
	radixSortTopDown(a, left, left + mid - 1, bitpos - 1);
	radixSortTopDown(a, left + mid, right, bitpos - 1);
}