Annotation of researchv10dc/vol2/anim/race.gen, revision 1.1.1.1

1.1       root        1: awk '
                      2: BEGIN {        n = 50
                      3:        for (i = 1; i <= n; i++) x[i] = int(100*rand())
                      4:        for (i = 1; i <= n; i++) draw(i)
                      5:        qsort(1, n) # or isort()
                      6: }
                      7: function draw(i)  {
                      8:     print "a" i ": line", i, -3, i, x[i]
                      9: }
                     10: function swap(i, j,   t) {
                     11:     t = x[i];  x[i] = x[j];  x[j] = t
                     12:     draw(i); draw(j)
                     13:     print "click swap"
                     14: }
                     15: function less(i, j) {
                     16:     print "click comp"
                     17:     if (x[i] < x[j]) return 1; else return 0
                     18: }
                     19: function isort(   i, j) {
                     20:     for (i = 2; i <= n; i++)
                     21:        for (j = i; j > 1 && less(j, j-1); j--)
                     22:            swap(j-1, j)
                     23: }
                     24: function qsort(l, u,   i, m) {
                     25:     if (l >= u) return
                     26:     swap(m = l, l + int((u-l+1)*rand()))
                     27:     for (i = l+1; i <= u; i++)
                     28:        if (less(i, l)) swap(++m, i)
                     29:     swap(l, m)
                     30:     qsort(l, m-1)
                     31:     qsort(m+1, u)
                     32: }'

unix.superglobalmegacorp.com

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