June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,70 @@
|
|||
.ig
|
||||
Bubble sort algorithm in Troff
|
||||
==============================
|
||||
|
||||
:For: Rosetta Code
|
||||
:Author: Stephanie Björk (Katt)
|
||||
:Date: December 1, 2017
|
||||
..
|
||||
.ig
|
||||
Array implementation: \(*A
|
||||
---------------------------
|
||||
This is an array implementation that takes advantage of Troff's numerical
|
||||
registers. Registers ``Ax``, where ``x`` is a base-10 Hindu-Arabic numeral and
|
||||
0 < ``x`` < \(if, are used by array \(*A. The array counter which holds the
|
||||
number of items in the array is stored in register ``Ac``. This array
|
||||
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.
|
||||
..
|
||||
.nr Ac 0 1 \" Array counter
|
||||
.
|
||||
.de APUSH
|
||||
.nr A\\n+(Ac \\$1
|
||||
.. \" de APUSH
|
||||
.
|
||||
.de AREADLN
|
||||
.APUSH \\$1
|
||||
.if \\n(.$>1 \{ \
|
||||
. shift
|
||||
. AREADLN \\$*
|
||||
\} \" if \\n(.$>1
|
||||
.. \" de AREADLN
|
||||
.
|
||||
.de ASWAP
|
||||
.nr tmp \\n[A\\$1]
|
||||
.nr A\\$1 \\n[A\\$2]
|
||||
.nr A\\$2 \\n[tmp]
|
||||
.rm tmp
|
||||
.. \" de ASWAP
|
||||
.
|
||||
.de ASORT
|
||||
.nr swapped 1
|
||||
.nr Ad \\n(Ac+1
|
||||
.while \\n[swapped] \{ \
|
||||
. nr swapped 0
|
||||
. nr Ai 1
|
||||
. nr Ad -1
|
||||
. while \\n(Ai<\\n(Ad \{ \
|
||||
. nr Aj \\n(Ai+1
|
||||
. if \\n[A\\n(Ai]>\\n[A\\n(Aj] \{ \
|
||||
. ASWAP \\n(Ai \\n(Aj
|
||||
. nr swapped 1
|
||||
\} \" if \\n[A\\n(Ai]>\\n[A\\n(Aj]
|
||||
. nr Ai +1
|
||||
\} \" while \\n(Ai<\\n(Ac
|
||||
\} \" while \\n[swapped]
|
||||
.. \" de ASORT
|
||||
.
|
||||
.ig
|
||||
Begin Program
|
||||
-------------
|
||||
The program's procedural body. Here, we push all our potentially-unsorted
|
||||
integer tokens sequentially, call a subroutine to sort them, and print all the
|
||||
sorted items.
|
||||
..
|
||||
.AREADLN 12 87 23 77 0 66 45 92 3 0 2 1 9 9 5 4 4 4 \" Our input items to sort.
|
||||
.ASORT \" Sort all items in the array.
|
||||
.
|
||||
.\" Output sorted items
|
||||
.nr Ai 0 1
|
||||
.while \n(Ai<\n(Ac \n[A\n+[Ai]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue