[Dinfio] Counting Sort in Dinfio - Muhammad Faruq Nuruddinsyah
[Dinfio] Counting Sort in Dinfio

Here's counting sort implementation in Dinfio Language.

Source Code:
' Counting Sort

start
	@a = @array(6)
	a[1] = 4; a[2] = 2; a[3] = 10; a[4] = 6; a[5] = 1
 
	@a = @counting_sort(@a, 10)
 
	for i, 1, size(@a) - 1
		write(a[i] & " ")
	endfor
stop
 
function @counting_sort(@a, k)
	n = size(@a) - 1
	@b = @array(n)
	@c = @array(k)
 
	for i, 1, n
		c[a[i]] = c[a[i]] + 1
	endfor
 
	c[-1] = 0
 
	for i, 0, k
		c[i] = c[i] + c[i - 1]
	endfor
 
	for i, n, 1, -1
		b[c[a[i]]] = a[i]
		c[a[i]] = c[a[i]] - 1
	endfor
 
	return @b
stop

Informasi:
Lihat semua daftar ACS - Download: counting-sort.fio - Tanggal: 10 Oktober 2016 - Kategori: Dinfio