{"id":89004,"date":"2024-02-15T06:13:13","date_gmt":"2024-02-14T22:13:13","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=89004"},"modified":"2024-02-15T06:13:13","modified_gmt":"2024-02-14T22:13:13","slug":"binary_search","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/binary_search.html","title":{"rendered":"\u7b97\u6cd5\u2014\u2014\u4e8c\u5206\u67e5\u627e\u8be6\u89e3"},"content":{"rendered":"
\u4e8c\u5206\u67e5\u627e\u53c8\u79f0\u6298\u534a\u67e5\u627e\uff0c\u4f18\u70b9<\/strong>\u662f\u6bd4\u8f83\u6b21\u6570\u5c11\uff0c\u67e5\u627e\u901f\u5ea6\u5feb\uff0c\u5e73\u5747\u6027\u80fd\u597d\uff0c\u5360\u7528\u7cfb\u7edf\u5185\u5b58\u8f83\u5c11\uff1b<\/p>\n \u5176\u7f3a\u70b9<\/strong>\u662f\u8981\u6c42\u5f85\u67e5\u8868\u4e3a\u6709\u5e8f\u8868\uff0c\u4e14\u63d2\u5165\u5220\u9664\u56f0\u96be\u3002<\/p>\n \u56e0\u6b64\uff0c\u6298\u534a\u67e5\u627e\u65b9\u6cd5\u9002\u7528\u4e8e\u4e0d\u7ecf\u5e38\u53d8\u52a8\u800c\u67e5\u627e\u9891\u7e41\u7684\u6709\u5e8f\u5217\u8868<\/strong>\u3002<\/p>\n \u9996\u5148\uff0c\u5047\u8bbe\u8868\u4e2d\u5143\u7d20\u662f\u6309\u5347\u5e8f\u6392\u5217\uff0c\u5c06\u8868\u4e2d\u95f4\u4f4d\u7f6e\u8bb0\u5f55\u7684\u5173\u952e\u5b57\u4e0e\u67e5\u627e\u5173\u952e\u5b57\u6bd4\u8f83\uff0c\u5982\u679c\u4e24\u8005\u76f8\u7b49\uff0c\u5219\u67e5\u627e\u6210\u529f\uff1b<\/p>\n \u5426\u5219\u5229\u7528\u4e2d\u95f4\u4f4d\u7f6e\u8bb0\u5f55\u5c06\u8868\u5206\u6210\u524d\u3001\u540e\u4e24\u4e2a\u5b50\u8868\uff0c\u5982\u679c\u4e2d\u95f4\u4f4d\u7f6e\u8bb0\u5f55\u7684\u5173\u952e\u5b57\u5927\u4e8e\u67e5\u627e\u5173\u952e\u5b57\uff0c\u5219\u8fdb\u4e00\u6b65\u67e5\u627e\u524d\u4e00\u5b50\u8868\uff0c\u5426\u5219\u8fdb\u4e00\u6b65\u67e5\u627e\u540e\u4e00\u5b50\u8868\u3002<\/p>\n \u91cd\u590d\u4ee5\u4e0a\u8fc7\u7a0b\uff0c\u76f4\u5230\u627e\u5230\u6ee1\u8db3\u6761\u4ef6\u7684\u8bb0\u5f55\uff0c\u4f7f\u67e5\u627e\u6210\u529f\uff0c\u6216\u76f4\u5230\u5b50\u8868\u4e0d\u5b58\u5728\u4e3a\u6b62\uff0c\u6b64\u65f6\u67e5\u627e\u4e0d\u6210\u529f\u3002<\/p>\n int binary_search(int *A,int n,int key) \u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.cnblogs.com\/wongyi\/p\/7782733.html<\/a><\/p>\n#include
\nusing namespace std;<\/p>\n
\n{
\n int left=0,right=n-1;
\n while(left< =right)\n {\n int mid=(left+right)>>1;
\n if(key==A[mid])
\n return mid;
\n else if(key>key;
\n cout< \n