Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
Line 2,585: Line 2,585:
This program may output to paper (Postscript/PDF or actual printout) or a line-printer/terminal depending on the device specification.
This program may output to paper (Postscript/PDF or actual printout) or a line-printer/terminal depending on the device specification.


This implementation is not reverse-compatible classical TROFF from Bell Labs, as TROFF then was extremely limited in what it could do. It will work with GNU Troff, though.
This implementation is not reverse-compatible classical TROFF from Bell Labs, as TROFF then was extremely limited in what it could do. It will work with GNU Troff, though. The classical version of TROFF could only do recursive macro calls, which is integral to the functioning of <code>.AREADLN</code>, but not <code>.while</code> looping constructs, which is integral to the functioning of <code>.ASORT</code>; it could also only support numerical registers with name consisting of two characters maximum, so a register named <code>A9</code> would be okay (2 characters), but not <code>A123</code> (4 characters).

Block comments start with <code>.ig</code> and end with <code>..</code>. Single-line comments begin with <code>\"</code>


{{works with|GROFF (GNU Troff)|1.22.2}}
{{works with|GROFF (GNU Troff)|1.22.2}}
Line 2,607: Line 2,609:
implementation is one-indexed (array elements count from 1), though it could be
implementation is one-indexed (array elements count from 1), though it could be
hardcoded again to become zero-indexed depending on what the programmer favours.
hardcoded again to become zero-indexed depending on what the programmer favours.

\&.. NOTE::
Only integer tokens ``n`` where 0 <= ``n`` < \(if, are allowed in \(*A.

.APUSH x
Push item ``x`` into array \(*A.
.AREADLN x..
Push items ``x..`` into array \(*A. This is a shortcut to many successive
calls of the ``.APUSH`` request.
.ASWAP i j
Swap between the ith and jth items of the array \(*A.
.ASORT
Sort all items in array \(*A using the bubble sort algorithm.
..
..
.nr Ac 0 1 \" Array counter
.nr Ac 0 1 \" Array counter