{"id":60183,"date":"2024-10-13T00:44:14","date_gmt":"2024-10-12T16:44:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/60183\/"},"modified":"2024-10-13T00:44:14","modified_gmt":"2024-10-12T16:44:14","slug":"c%e8%aa%9e%e8%a8%80%e5%af%a6%e7%8f%be%e8%87%aa%e8%a1%8c%e7%94%9f%e6%88%90%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%8c%e8%bc%95%e9%ac%86%e5%ad%98%e5%84%b2%e5%a4%a7%e9%87%8f%e6%95%b8%e6%93%9a-c%e8%87%aa","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/60183\/","title":{"rendered":"C\u8a9e\u8a00\u5be6\u73fe\u81ea\u884c\u751f\u6210\u6578\u64da\u5eab\uff0c\u8f15\u9b06\u5b58\u5132\u5927\u91cf\u6578\u64da (c\u81ea\u884c\u751f\u6210\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"c%e8%aa%9e%e8%a8%80%e5%af%a6%e7%8f%be%e8%87%aa%e8%a1%8c%e7%94%9f%e6%88%90%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%8c%e8%bc%95%e9%ac%86%e5%ad%98%e5%84%b2%e5%a4%a7%e9%87%8f%e6%95%b8%e6%93%9a-IBRhkWxUax\">C\u8a9e\u8a00\u5be6\u73fe\u81ea\u884c\u751f\u6210\u6578\u64da\u5eab\uff0c\u8f15\u9b06\u5b58\u5132\u5927\u91cf\u6578\u64da<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u6642\u4ee3\uff0c\u6578\u64da\u5eab\u7684\u7ba1\u7406\u548c\u5b58\u5132\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u96d6\u7136\u5e02\u9762\u4e0a\u6709\u8a31\u591a\u6210\u719f\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u53ef\u4f9b\u9078\u64c7\uff0c\u4f46\u6709\u6642\u5019\u958b\u767c\u8005\u53ef\u80fd\u9700\u8981\u4e00\u500b\u7c21\u55ae\u4e14\u9748\u6d3b\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528C\u8a9e\u8a00\u81ea\u884c\u751f\u6210\u4e00\u500b\u7c21\u55ae\u7684\u6578\u64da\u5eab\uff0c\u4e26\u8f15\u9b06\u5b58\u5132\u5927\u91cf\u6578\u64da\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87c%e8%aa%9e%e8%a8%80%ef%bc%9f-IBRhkWxUax\">\u70ba\u4ec0\u9ebc\u9078\u64c7C\u8a9e\u8a00\uff1f<\/h2>\n<p>C\u8a9e\u8a00\u662f\u4e00\u7a2e\u9ad8\u6548\u4e14\u9748\u6d3b\u7684\u7de8\u7a0b\u8a9e\u8a00\uff0c\u9069\u5408\u7528\u65bc\u7cfb\u7d71\u7de8\u7a0b\u548c\u5e95\u5c64\u958b\u767c\u3002\u5176\u512a\u52e2\u5728\u65bc\uff1a<\/p>\n<ul>\n<li>\u9ad8\u6548\u6027\u80fd\uff1aC\u8a9e\u8a00\u7684\u57f7\u884c\u901f\u5ea6\u5feb\uff0c\u9069\u5408\u8655\u7406\u5927\u91cf\u6578\u64da\u3002<\/li>\n<li>\u9748\u6d3b\u6027\uff1a\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u81ea\u5b9a\u7fa9\u6578\u64da\u7d50\u69cb\u548c\u5b58\u5132\u65b9\u5f0f\u3002<\/li>\n<li>\u5ee3\u6cdb\u7684\u61c9\u7528\uff1aC\u8a9e\u8a00\u5728\u5d4c\u5165\u5f0f\u7cfb\u7d71\u3001\u64cd\u4f5c\u7cfb\u7d71\u7b49\u9818\u57df\u6709\u8457\u5ee3\u6cdb\u7684\u61c9\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b5%90%e6%a7%8b-IBRhkWxUax\">\u57fa\u672c\u6578\u64da\u5eab\u7d50\u69cb<\/h2>\n<p>\u5728\u958b\u59cb\u7de8\u5beb\u4ee3\u78bc\u4e4b\u524d\uff0c\u6211\u5011\u9700\u8981\u8a2d\u8a08\u4e00\u500b\u7c21\u55ae\u7684\u6578\u64da\u5eab\u7d50\u69cb\u3002\u9019\u88e1\u6211\u5011\u5c07\u4f7f\u7528\u93c8\u8868\u4f86\u5b58\u5132\u6578\u64da\u3002\u6bcf\u500b\u7bc0\u9ede\u5c07\u5305\u542b\u6578\u64da\u548c\u6307\u5411\u4e0b\u4e00\u500b\u7bc0\u9ede\u7684\u6307\u91dd\u3002<\/p>\n<pre><code>\ntypedef struct Node {\n    int id;\n    char data[256];\n    struct Node* next;\n} Node;\n<\/code><\/pre>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c-IBRhkWxUax\">\u6578\u64da\u5eab\u64cd\u4f5c<\/h2>\n<p>\u6211\u5011\u5c07\u5be6\u73fe\u57fa\u672c\u7684\u6578\u64da\u5eab\u64cd\u4f5c\uff0c\u5305\u62ec\u63d2\u5165\u3001\u67e5\u8a62\u548c\u522a\u9664\u6578\u64da\u3002<\/p>\n<h3 id=\"%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-IBRhkWxUax\">\u63d2\u5165\u6578\u64da<\/h3>\n<pre><code>\nvoid insert(Node** head, int id, const char* data) {\n    Node* newNode = (Node*)malloc(sizeof(Node));\n    newNode-&gt;id = id;\n    strcpy(newNode-&gt;data, data);\n    newNode-&gt;next = *head;\n    *head = newNode;\n}\n<\/code><\/pre>\n<h3 id=\"%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-IBRhkWxUax\">\u67e5\u8a62\u6578\u64da<\/h3>\n<pre><code>\nNode* search(Node* head, int id) {\n    Node* current = head;\n    while (current != NULL) {\n        if (current-&gt;id == id) {\n            return current;\n        }\n        current = current-&gt;next;\n    }\n    return NULL;\n}\n<\/code><\/pre>\n<h3 id=\"%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-IBRhkWxUax\">\u522a\u9664\u6578\u64da<\/h3>\n<pre><code>\nvoid delete(Node** head, int id) {\n    Node* current = *head;\n    Node* previous = NULL;\n\n    while (current != NULL &amp;&amp; current-&gt;id != id) {\n        previous = current;\n        current = current-&gt;next;\n    }\n\n    if (current == NULL) return; \/\/ \u672a\u627e\u5230\n\n    if (previous == NULL) {\n        *head = current-&gt;next; \/\/ \u522a\u9664\u982d\u7bc0\u9ede\n    } else {\n        previous-&gt;next = current-&gt;next; \/\/ \u522a\u9664\u4e2d\u9593\u6216\u5c3e\u90e8\u7bc0\u9ede\n    }\n    free(current);\n}\n<\/code><\/pre>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e7%a4%ba%e4%be%8b-IBRhkWxUax\">\u6578\u64da\u5eab\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u4e0a\u8ff0\u51fd\u6578\u4f86\u64cd\u4f5c\u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>\nint main() {\n    Node* database = NULL;\n\n    insert(&amp;database, 1, \"\u6578\u64da1\");\n    insert(&amp;database, 2, \"\u6578\u64da2\");\n    insert(&amp;database, 3, \"\u6578\u64da3\");\n\n    Node* result = search(database, 2);\n    if (result) {\n        printf(\"\u627e\u5230\u6578\u64da: %sn\", result-&gt;data);\n    }\n\n    delete(&amp;database, 2);\n    result = search(database, 2);\n    if (!result) {\n        printf(\"\u6578\u64da\u5df2\u522a\u9664n\");\n    }\n\n    return 0;\n}\n<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-IBRhkWxUax\">\u7d50\u8ad6<\/h2>\n<p>\u901a\u904e\u4f7f\u7528C\u8a9e\u8a00\uff0c\u6211\u5011\u53ef\u4ee5\u8f15\u9b06\u5730\u5be6\u73fe\u4e00\u500b\u7c21\u55ae\u7684\u6578\u64da\u5eab\uff0c\u4e26\u9032\u884c\u57fa\u672c\u7684\u6578\u64da\u64cd\u4f5c\u3002\u9019\u7a2e\u65b9\u6cd5\u4e0d\u50c5\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7406\u89e3\u6578\u64da\u7d50\u69cb\u548c\u7b97\u6cd5\uff0c\u9084\u80fd\u5920\u5728\u7279\u5b9a\u9700\u6c42\u4e0b\u63d0\u4f9b\u9748\u6d3b\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\uff0c\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u6027\u548c\u53ef\u7528\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22C\u8a9e\u8a00\u5982\u4f55\u8f15\u9b06\u5be6\u73fe\u81ea\u52d5\u751f\u6210\u6578\u64da\u5eab\uff0c\u4fbf\u6377\u5b58\u5132\u548c\u7ba1\u7406\u5927\u91cf\u6578\u64da\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-60183","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/60183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=60183"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/60183\/revisions"}],"predecessor-version":[{"id":60184,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/60183\/revisions\/60184"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=60183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=60183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=60183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}