The array itself is small (up to 15 numbers). Consists of increasing elements. For example: [2 7 13 14 25 37 39 42 44 56 59 60 66] It is necessary to check whether the value of a digital variable is part of a numeric array.
- Iiiiii, what's the problem? Or you just can not loop through the array? - Flowneee
|
1 answer
It is necessary to go through all the elements of the array in a loop, comparing each element with a variable.
for example:
a=(2 7 13 14 25 37 39 42 44 56 59 60 66) v=39 for i in ${a[@]}; do if [ $v -eq $i ]; then echo "элемент $v входит в массив" break fi done - I’m a binary now here a binary search will be in response) - pavel 4:21 pm
- @pavel, well, computers, nonche, are binary, that's why the proposed search is completely binary. - aleksandr barakin
|