Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Binary-search/UNIX-Shell/binary-search-1.sh
Normal file
11
Task/Binary-search/UNIX-Shell/binary-search-1.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/ksh
|
||||
# This should work on any clone of Bourne Shell, ksh is the fastest.
|
||||
|
||||
value=$1; [ -z "$value" ] && exit
|
||||
array=()
|
||||
size=0
|
||||
|
||||
while IFS= read -r line; do
|
||||
size=$(($size + 1))
|
||||
array[${#array[*]}]=$line
|
||||
done
|
||||
15
Task/Binary-search/UNIX-Shell/binary-search-2.sh
Normal file
15
Task/Binary-search/UNIX-Shell/binary-search-2.sh
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
left=0
|
||||
right=$(($size - 1))
|
||||
while [ $left -le $right ] ; do
|
||||
mid=$((($left + $right) >> 1))
|
||||
# echo "$left $mid(${array[$mid]}) $right"
|
||||
if [ $value -eq ${array[$mid]} ] ; then
|
||||
echo $mid
|
||||
exit
|
||||
elif [ $value -lt ${array[$mid]} ]; then
|
||||
right=$(($mid - 1))
|
||||
else
|
||||
left=$((mid + 1))
|
||||
fi
|
||||
done
|
||||
echo 'ERROR 404 : NOT FOUND'
|
||||
1
Task/Binary-search/UNIX-Shell/binary-search-3.sh
Normal file
1
Task/Binary-search/UNIX-Shell/binary-search-3.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
No code yet
|
||||
Loading…
Add table
Add a link
Reference in a new issue