Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Binary-search/UnixPipes/binary-search.up
Normal file
18
Task/Binary-search/UnixPipes/binary-search.up
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
splitter() {
|
||||
a=$1; s=$2; l=$3; r=$4;
|
||||
mid=$(expr ${#a[*]} / 2);
|
||||
echo $s ${a[*]:0:$mid} > $l
|
||||
echo $(($mid + $s)) ${a[*]:$mid} > $r
|
||||
}
|
||||
|
||||
bsearch() {
|
||||
(to=$1; read s arr; a=($arr);
|
||||
test ${#a[*]} -gt 1 && (splitter $a $s >(bsearch $to) >(bsearch $to)) || (test "$a" -eq "$to" && echo $a at $s)
|
||||
)
|
||||
}
|
||||
|
||||
binsearch() {
|
||||
(read arr; echo "0 $arr" | bsearch $1)
|
||||
}
|
||||
|
||||
echo "1 2 3 4 6 7 8 9" | binsearch 6
|
||||
Loading…
Add table
Add a link
Reference in a new issue