{"action":"created","issue":{"url":"https://api.github.com/repos/waynewbishop/SwiftStructures/issues/75","labels_url":"https://api.github.com/repos/waynewbishop/SwiftStructures/issues/75/labels{/name}","comments_url":"https://api.github.com/repos/waynewbishop/SwiftStructures/issues/75/comments","events_url":"https://api.github.com/repos/waynewbishop/SwiftStructures/issues/75/events","html_url":"https://github.com/waynewbishop/SwiftStructures/issues/75","id":118201806,"number":75,"title":"Binary search should have condition to exit if the item doesn't exist in the array.","user":{"login":"kNeerajPro","id":7275348,"avatar_url":"https://avatars.githubusercontent.com/u/7275348?v=3","gravatar_id":"","url":"https://api.github.com/users/kNeerajPro","html_url":"https://github.com/kNeerajPro","followers_url":"https://api.github.com/users/kNeerajPro/followers","following_url":"https://api.github.com/users/kNeerajPro/following{/other_user}","gists_url":"https://api.github.com/users/kNeerajPro/gists{/gist_id}","starred_url":"https://api.github.com/users/kNeerajPro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kNeerajPro/subscriptions","organizations_url":"https://api.github.com/users/kNeerajPro/orgs","repos_url":"https://api.github.com/users/kNeerajPro/repos","events_url":"https://api.github.com/users/kNeerajPro/events{/privacy}","received_events_url":"https://api.github.com/users/kNeerajPro/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-21T15:02:47Z","updated_at":"2015-12-02T20:08:57Z","closed_at":"2015-12-02T20:08:57Z","body":"I have added a condition in the algorithm - \r\nfunc binarySearch(key:Int, imin: Int, imax:Int) {\r\n    let midIndex = (imin + imax) / 2\r\n    let midNumber = numberList[midIndex]\r\n   // Exit condition if the item doesn't exist in the array. \r\n   if (imin > imax) {\r\n        println(\"not found\")\r\n        return\r\n    }\r\n    if (midNumber > key) {\r\n       newBinarySearch(key, imin, midIndex - 1)\r\n    }\r\n    else if (midNumber < key) {\r\n        newBinarySearch(key, midIndex + 1, imax)\r\n    }\r\n    else {\r\n        println(\"value found at index : \\(midIndex)\")\r\n    }\r\n}"},"comment":{"url":"https://api.github.com/repos/waynewbishop/SwiftStructures/issues/comments/161418267","html_url":"https://github.com/waynewbishop/SwiftStructures/issues/75#issuecomment-161418267","issue_url":"https://api.github.com/repos/waynewbishop/SwiftStructures/issues/75","id":161418267,"user":{"login":"waynewbishop","id":128404,"avatar_url":"https://avatars.githubusercontent.com/u/128404?v=3","gravatar_id":"","url":"https://api.github.com/users/waynewbishop","html_url":"https://github.com/waynewbishop","followers_url":"https://api.github.com/users/waynewbishop/followers","following_url":"https://api.github.com/users/waynewbishop/following{/other_user}","gists_url":"https://api.github.com/users/waynewbishop/gists{/gist_id}","starred_url":"https://api.github.com/users/waynewbishop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/waynewbishop/subscriptions","organizations_url":"https://api.github.com/users/waynewbishop/orgs","repos_url":"https://api.github.com/users/waynewbishop/repos","events_url":"https://api.github.com/users/waynewbishop/events{/privacy}","received_events_url":"https://api.github.com/users/waynewbishop/received_events","type":"User","site_admin":false},"created_at":"2015-12-02T20:08:57Z","updated_at":"2015-12-02T20:08:57Z","body":"Hi Neera;\r\n\r\nThanks for your question. Binary Search, along with some other key algorithms have been refactored. The latest updates also include your question about a conditional exit. To see the change summary visit:\r\n\r\nhttps://github.com/waynewbishop/SwiftStructures/releases/tag/v.2.1\r\n\r\nThanks;\r\n\r\n-Wayne\r\n\r\n\r\n"}}