June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
38
Task/Binary-search/N-t-roff/binary-search.n
Normal file
38
Task/Binary-search/N-t-roff/binary-search.n
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
.de end
|
||||
..
|
||||
.de array
|
||||
. nr \\$1.c 0 1
|
||||
. de \\$1.push end
|
||||
. nr \\$1..\\\\n+[\\$1.c] \\\\$1
|
||||
. end
|
||||
. de \\$1.pushln end
|
||||
. if \\\\n(.$>0 .\\$1.push \\\\$1
|
||||
. if \\\\n(.$>1 \{ \
|
||||
. shift
|
||||
. \\$1.pushln \\\\$@
|
||||
\}
|
||||
. end
|
||||
..
|
||||
.
|
||||
.de binarysearch
|
||||
. nr min 1
|
||||
. nr max \\n[\\$1.c]
|
||||
. nr guess \\n[min]+\\n[max]/2
|
||||
. while !\\n[\\$1..\\n[guess]]=\\$2 \{ \
|
||||
. ie \\n[\\$1..\\n[guess]]<\\$2 .nr min \\n[guess]+1
|
||||
. el .nr max \\n[guess]-1
|
||||
.
|
||||
. if \\n[min]>\\n[max] \{
|
||||
. nr guess 0
|
||||
. break
|
||||
. \}
|
||||
. nr guess \\n[min]+\\n[max]/2
|
||||
. \}
|
||||
\\n[guess]
|
||||
..
|
||||
.array a
|
||||
.a.pushln 1 4 9 16 25 36 49 64 81 100 121 144
|
||||
.binarysearch a 100
|
||||
.br
|
||||
.ie \n[guess]=0 The item \fBdoesn't exist\fP.
|
||||
.el The item \fBdoes exist\fP.
|
||||
Loading…
Add table
Add a link
Reference in a new issue