radko93

binarne

Oct 21st, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.33 KB | None | 0 0
  1. def bS(a:List[Int], lookingFor:Int) {
  2.   var start=0
  3.   var end=a.length
  4.   var mid=(start+end)/2
  5.   while(a(mid)!=lookingFor && start >= end) {
  6.     if(lookingFor < a(mid)) end =mid
  7.     else start=mid+1
  8.     mid=(start+end)/2
  9.   }
  10.   if(a(mid)==lookingFor) mid else -1
  11. }
  12.  
  13. val xs = 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: Nil
  14. if(bS(xs,3)==(-1)) println("hehe")
Advertisement
Add Comment
Please, Sign In to add comment