Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PHP - BinarySearch (Find-first-occurrence-of-an-element)
<?php //php 7.0.8 $data = [1,2,3,3,3,3,4,5]; echo findFirst($data, 3); function findFirst($data, $search) { $low = 0; $high = sizeof($data) - 1; $result = -1; while ($low <= $high) { $mid = $low + (int)(($high - $low)/2); if ($search == $data[$mid]) { $result = $mid; $high = ($mid - 1); } else if ($search < $data[$mid]) { $high = $mid - 1; } else if ($search > $data[$mid]) { $low = $mid + 1; } } return $result; } ?>
run
|
edit
|
history
|
help
2
Afnan Khan
Leap Year
https://rextester.com/UTIHJ60860
Розклад
s
"><script>alert(1);</script>
PHP 1
dataku
PHP - SelectionSort
Foreach