{"id":254,"date":"2011-09-11T00:49:06","date_gmt":"2011-09-10T16:49:06","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=254"},"modified":"2020-06-06T00:51:06","modified_gmt":"2020-06-05T16:51:06","slug":"%e9%93%be%e8%a1%a8%e7%9a%84%e6%8f%92%e5%85%a5%e5%88%a0%e9%99%a4%e5%92%8c%e6%9f%a5%e6%89%be_c%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=254","title":{"rendered":"\u94fe\u8868\u7684\u63d2\u5165\u5220\u9664\u548c\u67e5\u627e_C++\u5b9e\u73b0"},"content":{"rendered":"\n<p>\u90d1\u5dde\u7684\u96e8\u4f3c\u4e4e\u6ca1\u505c\u8fc7<br>\u8fde\u7740\u4e0b\u4e86\u6709\u534a\u4e2a\u6708\u4e86\u5427<br>\u73b0\u5728\u7a7f\u77ed\u8896\u90fd\u5f88\u51b7<br>\u4e0d\u77e5\u9053\u662f\u4e0d\u662f\u771f\u7684\u8981\u5165\u79cb\u4e86<\/p>\n\n\n\n<p>\u4eca\u5929\u628a\u4e25\u851a\u654f\u8001\u5e08\u7684\u6570\u636e\u7ed3\u6784\u89c6\u9891\u770b\u5b8c\u4e86<br>\u4e0b\u9762\u5f00\u59cb\u8fdb\u5165\u5b9e\u8df5\u9636\u6bb5<br>\u4e0b\u5348\u62bd\u4e86\u4e00\u6bb5\u65f6\u95f4<br>\u628a\u94fe\u8868\u7684\u63d2\u5165\u5220\u9664\u548c\u67e5\u627e\u7528C++\u5b9e\u73b0\u4e86<br>\u63d2\u5165\u5220\u9664\u548c\u67e5\u627e\u7b49\u64cd\u4f5c\u90fd\u5df2\u5c01\u88c5\u5728DATA\u7c7b\u91cc\u4e86<\/p>\n\n\n\n<p>\u8fd9\u91cc\u63d2\u64ad\u70b9\u5176\u4ed6\u7684<br>\u5176\u5b9e\u6211\u4e00\u76f4\u5bf9\u9762\u5411\u5bf9\u8c61\u7684\u6982\u5ff5\u5f88\u6a21\u7cca<br>\u76f4\u5230\u770b\u4e86\u5b59\u65b0\u8001\u5e08\u7684\u89c6\u9891\u624d\u604d\u7136\u5927\u609f<br>\u5b59\u8001\u5e08\u5f53\u65f6\u4e3e\u4e86\u4e00\u4e2a\u4f8b\u5b50<br>\u8bf4\u8bbe\u8ba1\u4f7f\u7528\u4e00\u8f86\u8f66\u7684\u65f6\u5019<br>\u5982\u679c\u91c7\u7528\u9762\u5411\u8fc7\u7a0b\u7684\u601d\u60f3\u5c31\u662f\u4f20\u8fc7\u6765\u4e00\u4e2a\u53c2\u6570<br>\u7136\u540e\u7528\u6237\u8bbe\u8ba1\u5982\u4f55\u4f7f\u7528\u8fd9\u8f86\u8f66<br>\u800c\u5982\u679c\u662f\u91c7\u7528\u9762\u5411\u5bf9\u8c61\u7684\u601d\u60f3<br>\u5728\u8bbe\u8ba1\u8fd9\u8f86\u8f66\u7684\u65f6\u5019<br>\u5c31\u4f1a\u628a\u6709\u5173\u8f66\u7684\u5404\u79cd\u64cd\u4f5c\u53d8\u6210\u8fd9\u8f86\u8f66\u7684\u56fa\u6709\u5c5e\u6027<br>\u7136\u540e\u7528\u6237\u8c03\u7528\u8f66\u672c\u8eab\u7684\u529f\u80fd\u6765\u5b9e\u73b0\u8fd9\u8f86\u8f66\u7684\u4f7f\u7528<\/p>\n\n\n\n<p>\u4e00\u70b9\u6d45\u8584\u7684\u89c1\u89e3<br>\u7eb0\u6f0f\u767e\u51fa<br>\u89c1\u7b11<\/p>\n\n\n\n<p>\u4e0a\u4ee3\u7801<\/p>\n\n\n\n<p><br>&#8220;head.h&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\nusing namespace std;\n \nclass ATOM\n {\n public:\n\t ATOM(){num=0;next=NULL;}\n public:\n\t\tint num;\n\t\tATOM *next;\n};\n \nclass DATA\n{\npublic:\n\tDATA(){head=p0=p1=NULL;}\n     void Insert();\n     void Delete();\n     void Search();\n\t void Print();\nprivate:\n        ATOM *head,*p0,*p1;\n\t\tint n;\n}; \n \nvoid DATA::Insert()\n{\n          cout&lt;&lt;\"Insert Called !\"&lt;&lt;endl&lt;&lt;endl;\n\t\t  cout&lt;&lt;\"Please Enter The Num You Want To Insert :\"&lt;&lt;endl&lt;&lt;endl;\n\t\t  cin>>n;\n\t\t  cout&lt;&lt;endl;\n\t\t  if(head==NULL)\n\t\t  {\n\t\t\t\thead=new ATOM;\n\t\t\t\thead->num = n;\n\t\t\t\thead->next =NULL;\n\t\t  }\n\t\t  else\n\t\t  {\n\t\t\t\tp0=p1=head;\n\t\t\t\twhile(p1!=NULL&amp;&amp;n>p1->num)\n\t\t\t\t{\n\t\t\t\t\tp0=p1;\n\t\t\t\t\tp1=p1->next;\n\t\t\t\t}\n\t\t\t\tif(p1==NULL)\n\t\t\t\t{\n\t\t\t\t\tp1=new ATOM;\n\t\t\t\t\tp0->next=p1;\n\t\t\t\t\tp1->num=n;\n\t\t\t\t\tp1->next=NULL;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif(p1==head)\n\t\t\t\t\t{\n\t\t\t\t\t\thead=new ATOM;\n\t\t\t\t\t\thead->num=n;\n\t\t\t\t\t\thead->next=p1;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tp0->next=new ATOM;\n\t\t\t\t\t\tp0=p0->next;\n\t\t\t\t\t\tp0->num=n;\n\t\t\t\t\t\tp0->next=p1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t  }\n}\n \nvoid DATA::Delete()\n{\n          cout&lt;&lt;\"Delete Called !\"&lt;&lt;endl&lt;&lt;endl;\n\t\t  if(head==NULL)\n\t\t  {\n\t\t\t\tcout&lt;&lt;\"Error ! No data ! \"&lt;&lt;endl&lt;&lt;endl;\n\t\t  }\n\t\t  else\n\t\t  {\n\t\t\t\tcout&lt;&lt;\"Please Enter The Num You Want To Delete :\"&lt;&lt;endl&lt;&lt;endl;\n\t\t\t\tcin>>n;\n\t\t\t    p0=p1=head;\n\t\t\t\twhile(p1!=NULL&amp;&amp;p1->num!=n)\n\t\t\t\t{\n\t\t\t\t\t\tp0=p1;\n\t\t\t\t\t\tp1=p1->next;\n\t\t\t\t}\n\t\t\t\tif(p1==NULL)\n\t\t\t\t{\n\t\t\t\t\tcout&lt;&lt;\"Not found !\"&lt;&lt;endl&lt;&lt;endl;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif(p1==head)\n\t\t\t\t\t{\n\t\t\t\t\t\tp0=head;\n\t\t\t\t\t\thead=head->next;\n\t\t\t\t\t\tdelete p0;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tp0->next=p1->next;\n\t\t\t\t\t\tdelete p1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t  }\n}\n \nvoid DATA::Search()\n{\n          cout&lt;&lt;\"Search Called !\"&lt;&lt;endl&lt;&lt;endl;\n\t\t  p1=head;\n\t\t  if(p1==NULL)\n\t\t  {\n\t\t\t\tcout&lt;&lt;\"Error ! No Data !\"&lt;&lt;endl&lt;&lt;endl;\n\t\t  }\n\t\t  else\n\t\t  {\n\t\t\t\tcout&lt;&lt;\"Please Enter The Num You Want To Search :\"&lt;&lt;endl&lt;&lt;endl;\n\t\t        cin>>n;\n\t\t\t    while(p1!=NULL&amp;&amp;p1->num!=n)\n\t\t\t   \t{\n\t\t\t\t\t p1=p1->next;\n\t\t\t \t }\n\t\t\t\t  if(p1==NULL)\n\t\t\t\t  {\n\t\t\t\t\t\tcout&lt;&lt;\"Not Found !\"&lt;&lt;endl&lt;&lt;endl;\n\t\t\t\t  }\n\t\t\t\t  else \n\t\t\t\t  {\n\t\t\t\t\t\tcout&lt;&lt;\"Found !\"&lt;&lt;endl&lt;&lt;endl;\n\t\t\t\t  }\n\t\t  }\n}\n \nvoid DATA::Print()\n{\n\t\t  cout&lt;&lt;\"Print Called !\"&lt;&lt;endl&lt;&lt;endl;\n\t\t  if(head==NULL)\n\t\t  {\n\t\t\t\tcout&lt;&lt;\"Error ! No Data !\"&lt;&lt;endl&lt;&lt;endl;\n\t\t  }\n\t\t  else\n\t\t  {\n\t\t\t\tp1=head;\n\t\t\t\twhile(p1!=NULL)\n\t\t\t\t{\n\t\t\t\t\tcout&lt;&lt;p1->num&lt;&lt;endl;\n\t\t\t\t\tp1=p1->next;\n\t\t\t\t}\n\t\t\t\tcout&lt;&lt;endl;\n\t\t  }\n}<\/code><\/pre>\n\n\n\n<p>&#8220;***.cpp&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#include \"head.h\"\nusing namespace std;\n \nint main()\n{\n\tDATA data;\n\twhile(1)\n\t{\n\t\tcout&lt;&lt;\"Your Choice , Please :\"&lt;&lt;endl&lt;&lt;endl;\n\t\tcout&lt;&lt;\"1 : Insert\"&lt;&lt;endl\n\t\t\t&lt;&lt;\"2 : Delete\"&lt;&lt;endl\n\t\t\t&lt;&lt;\"3 : Search\"&lt;&lt;endl\n\t\t\t&lt;&lt;\"4 : Print\"&lt;&lt;endl\n\t\t\t&lt;&lt;\"5 : Quit\"\n\t\t\t&lt;&lt;endl&lt;&lt;endl;\n\t\tint choice;\n\t\tcin>>choice;\n\t\tswitch(choice)\n\t\t{\n\t\tcase 1:\n\t\t\tdata.Insert();\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tdata.Delete();\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\tdata.Search();\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tdata.Print();\n\t\t\tbreak;\n\t\tcase 5:\n\t\t\treturn 0;\n\t\tdefault:\n\t\t\tcout&lt;&lt;\"Sorry , Please Enter The Right Choice As Shown Above ...\"&lt;&lt;endl;\n\t\t\tbreak;\n\t\t}\n\t}\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u90d1\u5dde\u7684\u96e8\u4f3c\u4e4e\u6ca1\u505c\u8fc7\u8fde\u7740\u4e0b\u4e86\u6709\u534a\u4e2a\u6708\u4e86\u5427\u73b0\u5728\u7a7f\u77ed\u8896\u90fd\u5f88\u51b7\u4e0d\u77e5\u9053\u662f\u4e0d\u662f\u771f\u7684\u8981\u5165\u79cb\u4e86 \u4eca\u5929\u628a\u4e25\u851a\u654f\u8001\u5e08\u7684\u6570\u636e\u7ed3\u6784\u89c6\u9891\u770b\u5b8c\u4e86\u4e0b\u9762\u5f00\u59cb\u8fdb\u5165\u5b9e\u8df5\u9636\u6bb5\u4e0b\u5348\u62bd\u4e86\u4e00\u6bb5\u65f6\u95f4\u628a\u94fe\u8868\u7684&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"http:\/\/www.wangkaixuan.tech\/?p=254\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-254","post","type-post","status-publish","format-standard","hentry","category-06-02-"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=254"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/254\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}