{"id":762,"date":"2024-11-07T12:46:24","date_gmt":"2024-11-07T04:46:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/762\/"},"modified":"2024-11-07T12:46:24","modified_gmt":"2024-11-07T04:46:24","slug":"c%e8%af%ad%e8%a8%80%e7%ae%97%e6%b3%95%ef%bc%9a%e7%ae%97%e6%b3%95%e4%b8%8e%e6%95%b0%e6%8d%ae%e7%a7%91%e5%ad%a6%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/762\/","title":{"rendered":"C\u8bed\u8a00\u7b97\u6cd5\uff1a\u7b97\u6cd5\u4e0e\u6570\u636e\u79d1\u5b66\u5b9e\u6218"},"content":{"rendered":"<p>c\u8bed\u8a00\u7b97\u6cd5\u5728\u6570\u636e\u79d1\u5b66\u4e2d\u5e7f\u6cdb\u5e94\u7528\uff0c\u4e3b\u8981\u7c7b\u578b\u5305\u62ec\u6392\u5e8f\u3001\u641c\u7d22\u3001\u6811\u548c\u56fe\u7b97\u6cd5\u3002\u5b9e\u6218\u6848\u4f8b\u5c55\u793a\u4e86\u5192\u6ce1\u6392\u5e8f\u3001\u4e8c\u5206\u67e5\u627e\u548c\u6700\u5c0f\u751f\u6210\u6811\u7684\u5b9e\u73b0\u3002c\u8bed\u8a00\u7b97\u6cd5\u56e0\u5176\u9ad8\u6027\u80fd\u3001\u8de8\u5e73\u53f0\u6027\u548c\u7075\u6d3b\u7684\u5185\u5b58\u7ba1\u7406\u800c\u6df1\u53d7\u9752\u7750\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1151\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172837242438936.jpg\" width=\"720\" height=\"288\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172837242438936.jpg 720w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172837242438936-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172837242438936-670x268.jpg 670w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" title=\"C\u8bed\u8a00\u7b97\u6cd5\uff1a\u7b97\u6cd5\u4e0e\u6570\u636e\u79d1\u5b66\u5b9e\u6218\u63d2\u56fe\" alt=\"C\u8bed\u8a00\u7b97\u6cd5\uff1a\u7b97\u6cd5\u4e0e\u6570\u636e\u79d1\u5b66\u5b9e\u6218\u63d2\u56fe\" \/><\/p>\n<p><strong>C \u8bed\u8a00\u7b97\u6cd5\uff1a\u7b97\u6cd5\u4e0e\u6570\u636e\u79d1\u5b66\u5b9e\u6218<\/strong><\/p>\n<p>\u5728\u6570\u636e\u79d1\u5b66\u9886\u57df\uff0c\u7b97\u6cd5\u53d1\u6325\u7740\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002C \u8bed\u8a00\u56e0\u5176\u9ad8\u6027\u80fd\u548c\u8de8\u5e73\u53f0\u6027\uff0c\u6210\u4e3a\u5b9e\u73b0\u7b97\u6cd5\u7684\u7406\u60f3\u9009\u62e9\u3002<\/p>\n<h3>\u7b97\u6cd5\u7c7b\u578b<\/h3>\n<p>C \u8bed\u8a00\u7b97\u6cd5\u4e3b\u8981\u5206\u4e3a\u4ee5\u4e0b\u7c7b\u578b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201cC\u8bed\u8a00\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b<\/p>\n<ul>\n<li> <strong>\u6392\u5e8f\u7b97\u6cd5\uff1a<\/strong> bubble sort\u3001selection sort\u3001insertion sort\u3001merge sort\u3001quick sort<\/li>\n<li> <strong>\u641c\u7d22\u7b97\u6cd5\uff1a<\/strong> linear search\u3001binary search<\/li>\n<li> <strong>\u6811\u7b97\u6cd5\uff1a<\/strong> binary tree\u3001AVL tree\u3001Red-Black tree<\/li>\n<li> <strong>\u56fe\u7b97\u6cd5\uff1a<\/strong> breadth-first search\u3001depth-first search\u3001Dijkstra\u3001Prim<\/li>\n<\/ul>\n<h3>\u5b9e\u6218\u6848\u4f8b<\/h3>\n<p><strong>\u6848\u4f8b 1\uff1a\u5192\u6ce1\u6392\u5e8f\u7b97\u6cd5<\/strong><\/p>\n<pre>void bubble_sort(int* arr, int n) {\n    for (int i = 0; i  arr[j + 1]) {\n                int temp = arr[j];\n                arr[j] = arr[j + 1];\n                arr[j + 1] = temp;\n            }\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6848\u4f8b 2\uff1a\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5<\/strong><\/p>\n<pre>int binary_search(int* arr, int n, int key) {\n    int low = 0;\n    int high = n - 1;\n\n    while (low  key) {\n            high = mid - 1;\n        } else {\n            low = mid + 1;\n        }\n    }\n\n    return -1;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6848\u4f8b 3\uff1a\u6700\u5c0f\u751f\u6210\u6811\u7b97\u6cd5<\/strong><\/p>\n<pre>struct Edge {\n    int src;\n    int dest;\n    int weight;\n};\n\nint find(int parent[], int i) {\n    if (parent[i] == i) {\n        return i;\n    }\n\n    return find(parent, parent[i]);\n}\n\nvoid union(int parent[], int rank[], int x, int y) {\n    int xroot = find(parent, x);\n    int yroot = find(parent, y);\n\n    if (rank[xroot]  rank[yroot]) {\n        parent[yroot] = xroot;\n    } else {\n        parent[yroot] = xroot;\n        rank[xroot]++;\n    }\n}\n\nint mst_kruskal(struct Edge edges[], int n, int E) {\n    int parent[n];\n    int rank[n];\n\n    for (int i = 0; i &lt;h3&gt;\u4f18\u52bf&lt;\/h3&gt;&lt;p&gt;\u4f7f\u7528 C \u8bed\u8a00\u7b97\u6cd5\u5177\u6709\u4ee5\u4e0b\u4f18\u52bf\uff1a&lt;\/p&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u9ad8\u6027\u80fd<\/li>\n<li>\u8de8\u5e73\u53f0\u6027<\/li>\n<li>\u4ee3\u7801\u7684\u53ef\u8bfb\u6027<\/li>\n<li>\u5185\u5b58\u7ba1\u7406\u7075\u6d3b\u6027<\/li>\n<\/ul>\n<h3>\u603b\u7ed3<\/h3>\n<p>C \u8bed\u8a00\u7b97\u6cd5\u5728\u6570\u636e\u79d1\u5b66\u9886\u57df\u53d1\u6325\u7740\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002\u4e86\u89e3\u5e38\u89c1\u7684\u7b97\u6cd5\u7c7b\u578b\u548c\u901a\u8fc7\u5b9e\u9645\u6848\u4f8b\u7ec3\u4e60\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6570\u636e\u79d1\u5b66\u5bb6\u89e3\u51b3\u590d\u6742\u7684\u95ee\u9898\u5e76\u4ece\u6570\u636e\u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u89c1\u89e3\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fC\u8bed\u8a00\u7b97\u6cd5\uff1a\u7b97\u6cd5\u4e0e\u6570\u636e\u79d1\u5b66\u5b9e\u6218\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>c\u8bed\u8a00\u7b97\u6cd5\u5728\u6570\u636e\u79d1\u5b66\u4e2d\u5e7f\u6cdb\u5e94\u7528\uff0c\u4e3b\u8981\u7c7b\u578b\u5305\u62ec\u6392\u5e8f\u3001\u641c\u7d22\u3001\u6811\u548c\u56fe\u7b97\u6cd5\u3002\u5b9e\u6218\u6848\u4f8b\u5c55\u793a\u4e86\u5192\u6ce1\u6392\u5e8f\u3001\u4e8c\u5206\u67e5\u627e\u548c\u6700\u5c0f\u751f\u6210\u6811\u7684\u5b9e\u73b0\u3002c\u8bed\u8a00\u7b97\u6cd5\u56e0\u5176\u9ad8\u6027\u80fd\u3001\u8de8\u5e73\u53f0\u6027\u548c\u7075\u6d3b\u7684\u5185\u5b58\u7ba1\u7406\u800c\u6df1\u53d7\u9752\u7750\u3002 C \u8bed\u8a00\u7b97\u6cd5\uff1a\u7b97\u6cd5\u4e0e\u6570\u636e\u79d1\u5b66\u5b9e\u6218 \u5728\u6570\u636e\u79d1\u5b66\u9886\u57df\uff0c\u7b97\u6cd5\u53d1\u6325\u7740\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002C \u8bed\u8a00\u56e0\u5176\u9ad8\u6027\u80fd\u548c\u8de8\u5e73\u53f0\u6027\uff0c\u6210\u4e3a\u5b9e\u73b0\u7b97\u6cd5\u7684\u7406\u60f3\u9009\u62e9\u3002 \u7b97\u6cd5\u7c7b\u578b C \u8bed\u8a00\u7b97\u6cd5\u4e3b\u8981\u5206\u4e3a\u4ee5\u4e0b\u7c7b\u578b\uff1a \u7acb\u5373\u5b66\u4e60\u201cC\u8bed\u8a00\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b \u6392\u5e8f\u7b97\u6cd5\uff1a bubble sort\u3001selection sort\u3001insertion sort\u3001merge sort\u3001quick sort \u641c\u7d22\u7b97\u6cd5\uff1a linear search\u3001binary search \u6811\u7b97\u6cd5\uff1a binary tree\u3001AVL tree\u3001Red-Black tree \u56fe\u7b97\u6cd5\uff1a breadth-first search\u3001depth-first search\u3001Dijkstra\u3001Prim \u5b9e\u6218\u6848\u4f8b \u6848\u4f8b 1\uff1a\u5192\u6ce1\u6392\u5e8f\u7b97\u6cd5 void bubble_sort(int* arr, int n) { for (int i = 0; i arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-762","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=762"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/762\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}