One day, I wanted to use binary search in one of my feature in my project. My friend said the algorithm was not easy to implement bug free. I did’t believe that. I spent 10min to write it.
1 | def search(list: Array[Int], start: Int, end: Int, x: Int): Option[Int] = { |
Ooh, definitly my code has bug, yes I admitted that it was not very easy to implement binary search bug free.
I revised it.
1 | def search(list: Array[Int], start: Int, end: Int, x: Int): Option[Int] = { |
1 | output: |
It was an interesting problem. I should tain my programming skills more.