File:  [Research Unix] / researchv10dc / vol2 / anim / is.awk
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:34 2018 UTC (8 years, 3 months ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Dan Cross

awk '
BEGIN {	n = ARGV[1]	# numer of elements to generate and sort
	for (i = 1; i <= n; i++) x[i] = 1 + int(25*rand())
	for (i = 2; i <= n; i++) {
		for (j = i; j > 1 && x[j] < x[j-1]; j--)
			swap(j-1, j)
		show()
	}
}
function swap(i, j,   t) {
	t = x[i];  x[i] = x[j];  x[j] = t
}
function show(  i) {
	for (i = 1; i <= n; i++)
		printf("%3d", x[i])
	printf("\n")
}' $*

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.