{"id":1,"date":"2017-01-17T09:30:21","date_gmt":"2017-01-17T00:30:21","guid":{"rendered":"http:\/\/kpc2017.satoshis.jp\/?p=1"},"modified":"2021-09-23T17:27:41","modified_gmt":"2021-09-23T08:27:41","slug":"hello-world","status":"publish","type":"post","link":"https:\/\/kpc2017.satoshis.jp\/?p=1","title":{"rendered":"\u7dda\u5f62\u30ea\u30b9\u30c8"},"content":{"rendered":"<p>Member.h \u306f\u3001\u30c6\u30ad\u30b9\u30c8p.114\u306b\u63b2\u8f09\u3002<br \/>\nMember.c \u306f\u3001\u30c6\u30ad\u30b9\u30c8p.115\u306b\u63b2\u8f09\u3002<\/p>\n<p>LinkedList.h \u306f\u3001\u30c6\u30ad\u30b9\u30c8p.337\u306b\u63b2\u8f09\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#ifndef ___LinkedList\r\n#define ___LinkedList\r\n\r\n#include &quot;Member.h&quot;\r\n\r\ntypedef struct __node {\r\n\tMember data;\r\n\tstruct __node *next;\r\n} Node;\r\n\r\ntypedef struct {\r\n\tNode *head;\r\n\tNode *crnt;\r\n} List;\r\n\r\nvoid Initialize(List *list);\r\n\r\nNode *Search(List *list, const Member *x, int compare(const Member *x, const Member *y));\r\n\r\nvoid InsertFront(List *list, const Member *x);\r\n\r\nvoid InsertRear(List *list, const Member *x);\r\n\r\nvoid RemoveFront(List *list);\r\n\r\nvoid RemoveRear(List *list);\r\n\r\nvoid RemoveCurrent(List *list);\r\n\r\nvoid Clear(List *list);\r\n\r\nvoid PrintCurrent(const List *list);\r\n\r\nvoid PrintLnCurrent(const List *list);\r\n\r\nvoid Print(const List *list);\r\n\r\nvoid Terminate(List *list);\r\n\r\n#endif\r\n<\/pre>\n<p>LinkedList.c<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n#include &quot;Member.h&quot;\r\n#include &quot;LinkedList.h&quot;\r\n\r\nstatic Node *AllocNode(void)\r\n{\r\n\treturn calloc(1, sizeof(Node));\r\n}\r\n\r\nstatic void SetNode(Node *n, const Member *x, const Node *next)\r\n{\r\n\tn-&gt;data = *x;\r\n\tn-&gt;next = next;\r\n}\r\n\r\nvoid Initialize(List *list)\r\n{\r\n\tlist-&gt;head = NULL;\r\n\tlist-&gt;crnt = NULL;\r\n}\r\n\r\nNode *Search(List *list, const Member *x, int compare(const Member *x, const Member *y))\r\n{\r\n\tNode *ptr = list-&gt;head;\r\n\twhile (ptr != NULL) {\r\n\t\tif (compare(&amp;ptr-&gt;data, x) == 0) {\r\n\t\t\tlist-&gt;crnt = ptr;\r\n\t\t\treturn ptr;\r\n\t\t}\r\n\t\tptr = ptr-&gt;next;\r\n\t}\r\n\treturn NULL;\r\n}\r\n\r\nvoid InsertFront(List *list, const Member *x)\r\n{\r\n\tNode *ptr = list-&gt;head;\r\n\tlist-&gt;head = list-&gt;crnt = AllocNode();\r\n\tSetNode(list-&gt;head, x, ptr);\r\n}\r\n\r\nvoid InsertRear(List *list, const Member *x)\r\n{\r\n\tif (list-&gt;head == NULL)\r\n\t\tInsertFront(list, x);\r\n\telse {\r\n\t\tNode *ptr = list-&gt;head;\r\n\t\twhile (ptr-&gt;next != NULL)\r\n\t\t\tptr = ptr-&gt;next;\r\n\t\tptr-&gt;next = list-&gt;crnt = AllocNode();\r\n\t\tSetNode(ptr-&gt;next, x, NULL);\r\n\t}\r\n}\r\n\r\nvoid RemoveFront(List *list)\r\n{\r\n\tif (list-&gt;head != NULL) {\r\n\t\tNode *ptr = list-&gt;head-&gt;next;\r\n\t\tfree(list-&gt;head);\r\n\t\tlist-&gt;head = list-&gt;crnt = ptr;\r\n\t}\r\n}\r\n\r\nvoid RemoveRear(List *list)\r\n{\r\n\tif (list-&gt;head != NULL) {\r\n\t\tif ((list-&gt;head)-&gt;next == NULL)\r\n\t\t\tRemoveFront(list);\r\n\t\telse {\r\n\t\t\tNode *ptr = list-&gt;head;\r\n\t\t\tNode *pre;\r\n\t\t\twhile (ptr-&gt;next != NULL) {\r\n\t\t\t\tpre = ptr;\r\n\t\t\t\tptr = ptr-&gt;next;\r\n\t\t\t}\r\n\t\t\tpre-&gt;next = NULL;\r\n\t\t\tfree(ptr);\r\n\t\t\tlist-&gt;crnt = pre;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nvoid RemoveCurrent(List *list)\r\n{\r\n\tif (list-&gt;head != NULL) {\r\n\t\tif (list-&gt;crnt == list-&gt;head)\r\n\t\t\tRemoveFront(list);\r\n\t\telse {\r\n\t\t\tNode *ptr = list-&gt;head;\r\n\t\t\twhile (ptr-&gt;next != list-&gt;crnt)\r\n\t\t\t\tptr = ptr-&gt;next;\r\n\t\t\tptr-&gt;next = list-&gt;crnt-&gt;next;\r\n\t\t\tfree(list-&gt;crnt);\r\n\t\t\tlist-&gt;crnt = ptr;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nvoid Clear(List *list)\r\n{\r\n\twhile (list-&gt;head != NULL)\r\n\t\tRemoveFront(list);\r\n\tlist-&gt;crnt = NULL;\r\n}\r\n\r\nvoid PrintCurrent(const List *list)\r\n{\r\n\tif (list-&gt;crnt == NULL)\r\n\t\tprintf(&quot;\u7740\u76ee\u30ce\u30fc\u30c9\u306f\u3042\u308a\u307e\u305b\u3093\u3002&quot;);\r\n\telse \r\n\t\tPrintMember(&amp;list-&gt;crnt-&gt;data);\r\n}\r\n\r\nvoid PrintLnCurrent(const List *list)\r\n{\r\n\tPrintCurrent(list);\r\n\tputchar('\\n');\r\n}\r\n\r\nvoid Print(const List *list)\r\n{\r\n\tif (list-&gt;head == NULL)\r\n\t\tputs(&quot;\u30ce\u30fc\u30c9\u304c\u3042\u308a\u307e\u305b\u3093\u3002&quot;);\r\n\telse {\r\n\t\tNode *ptr = list-&gt;head;\r\n\t\twhile (ptr != NULL) {\r\n\t\t\tPrintLnMember(&amp;ptr-&gt;data);\r\n\t\t\tptr = ptr-&gt;next;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nvoid Terminate(List *list)\r\n{\r\n\tClear(list);\r\n}\r\n<\/pre>\n<p>LinkedListTest.c<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &quot;Member.h&quot;\r\n#include &quot;LinkedList.h&quot;\r\n\r\ntypedef enum {\r\n\tTERMINATE, INS_FRONT, INS_REAR, RMV_FRONT, RMV_REAR, PRINT_CRNT,\r\n\tRMV_CRNT, SRCH_NO, SRCH_NAME, PRINT_ALL, CLEAR\r\n} Menu;\r\n\r\nMenu SelectMenu(void)\r\n{\r\n\tint i, ch;\r\n\tchar *mstring[] = {\r\n\t\t&quot;\u5148\u982d\u306b\u30ce\u30fc\u30c9\u3092\u633f\u5165&quot;, &quot;\u672b\u5c3e\u306b\u30ce\u30fc\u30c9\u3092\u633f\u5165&quot;, &quot;\u5148\u982d\u306e\u30ce\u30fc\u30c9\u3092\u524a\u9664&quot;,\r\n\t\t&quot;\u672b\u5c3e\u306e\u30ce\u30fc\u30c9\u3092\u524a\u9664&quot;, &quot;\u7740\u76ee\u30ce\u30fc\u30c9\u3092\u8868\u793a&quot;, &quot;\u7740\u76ee\u30ce\u30fc\u30c9\u3092\u524a\u9664&quot;,\r\n\t\t&quot;\u756a\u53f7\u3067\u63a2\u7d22&quot;, &quot;\u6c0f\u540d\u3067\u63a2\u7d22&quot;, &quot;\u5168\u30ce\u30fc\u30c9\u3092\u8868\u793a&quot;,\r\n\t\t&quot;\u5168\u30ce\u30fc\u30c9\u3092\u524a\u9664&quot;,\r\n\t};\r\n\r\n\tdo {\r\n\t\tfor (i = TERMINATE; i &lt; CLEAR; i++) {\r\n\t\t\tprintf(&quot;(%2d) %-18.18s  &quot;, i+1, mstring[i]);\r\n\t\t\tif ((i % 3) == 2) putchar('\\n');\r\n\t\t}\r\n\t\tprintf(&quot;( 0) \u7d42\u4e86 :&quot;);\r\n\t\tfflush(stdin);\r\n\t\tscanf_s(&quot;%d&quot;, &amp;ch);\r\n\t} while (ch &lt; TERMINATE || ch &gt; CLEAR);\r\n\treturn (Menu)ch;\r\n}\r\n\r\nint main(void)\r\n{\r\n\tMenu menu;\r\n\tList list;\r\n\r\n\tInitialize(&amp;list);\r\n\tdo{\r\n\t\tMember x;\r\n\t\tswitch(menu = SelectMenu()) {\r\n\t\tcase INS_FRONT :\r\n\t\t\tx = ScanMember(&quot;\u5148\u982d\u306b\u633f\u5165&quot;, MEMBER_NO | MEMBER_NAME);\r\n\t\t\tPrintMember(&amp;x);\r\n\t\t\tInsertFront(&amp;list, &amp;x);\r\n\t\t\tbreak;\r\n\t\tcase INS_REAR:\r\n\t\t\tx = ScanMember(&quot;\u672b\u5c3e\u306b\u633f\u5165&quot;, MEMBER_NO | MEMBER_NAME);\r\n\t\t\tInsertRear(&amp;list, &amp;x);\r\n\t\t\tbreak;\r\n\t\tcase RMV_FRONT:\r\n\t\t\tRemoveFront(&amp;list);\r\n\t\t\tbreak;\r\n\t\tcase PRINT_CRNT:\r\n\t\t\tPrintLnCurrent(&amp;list);\r\n\t\t\tbreak;\r\n\t\tcase RMV_REAR:\r\n\t\t\tRemoveRear(&amp;list);\r\n\t\t\tbreak;\r\n\t\tcase RMV_CRNT:\r\n\t\t\tRemoveCurrent(&amp;list);\r\n\t\t\tbreak;\r\n\t\tcase SRCH_NO:\r\n\t\t\tx = ScanMember(&quot;\u63a2\u7d22&quot;, MEMBER_NO);\r\n\t\t\tif (Search(&amp;list, &amp;x, MemberNoCmp) != NULL)\r\n\t\t\t\tPrintLnCurrent(&amp;list);\r\n\t\t\telse\r\n\t\t\t\tputs(&quot;\u305d\u306e\u756a\u53f7\u306e\u30c7\u30fc\u30bf\u306f\u3042\u308a\u307e\u305b\u3093\u3002&quot;);\r\n\t\t\tbreak;\r\n\t\tcase SRCH_NAME:\r\n\t\t\tx = ScanMember(&quot;\u63a2\u7d22&quot;, MEMBER_NAME);\r\n\t\t\tif (Search(&amp;list, &amp;x, MemberNameCmp) != NULL)\r\n\t\t\t\tPrintLnCurrent(&amp;list);\r\n\t\t\telse\r\n\t\t\t\tputs(&quot;\u305d\u306e\u540d\u524d\u306e\u30c7\u30fc\u30bf\u306f\u3042\u308a\u307e\u305b\u3093\u3002&quot;);\r\n\t\t\tbreak;\r\n\t\tcase PRINT_ALL:\r\n\t\t\tPrint(&amp;list);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t} while (menu != TERMINATE);\r\n\tTerminate(&amp;list);\r\n\treturn 0;\r\n}\r\n<\/pre>\n<p>Member.c<\/p>\n<p>scanf() \u3092 scanf_s()\u306b\u5909\u66f4\u3057\u3066\u3044\u308b\u305f\u3081\u300130\u884c\u76ee\u306e\u547c\u3073\u51fa\u3057\u90e8\u5206\u306b\u6587\u5b57\u6570\u4e0a\u9650\u306e\u5f15\u6570\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: cpp; highlight: [30]; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;string.h&gt;\r\n#include &quot;Member.h&quot;\r\n\r\nint MemberNoCmp(const Member *x, const Member *y)\r\n{\r\n\treturn x-&gt;no &lt; y-&gt;no ? -1 : x-&gt;no &gt; y-&gt;no ? 1 : 0;\r\n}\r\n\r\nint MemberNameCmp(const Member *x, const Member *y)\r\n{\r\n\treturn strcmp(x-&gt;name, y-&gt;name);\r\n}\r\n\r\nvoid PrintMember(const Member *x)\r\n{\r\n\tprintf(&quot;%d %s&quot;, x-&gt;no, x-&gt;name);\r\n}\r\n\r\nvoid PrintLnMember(const Member *x) \r\n{\r\n\tprintf(&quot;%d %s\\n&quot;, x-&gt;no, x-&gt;name);\r\n}\r\n\r\nMember ScanMember(const char *message, int sw) \r\n{\r\n\tMember temp;\r\n\tprintf(&quot;%s\u3059\u308b\u30c7\u30fc\u30bf\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\\n&quot;, message);\r\n\tif (sw &amp; MEMBER_NO)   { printf(&quot;\u756a\u53f7\uff1a&quot;); scanf_s(&quot;%d&quot;, &amp;temp.no); }\r\n\tif (sw &amp; MEMBER_NAME) { printf(&quot;\u6c0f\u540d\uff1a&quot;); scanf_s(&quot;%s&quot;, temp.name, 20); }\r\n\treturn temp;\r\n}\r\n<\/pre>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Member.h \u306f\u3001\u30c6\u30ad\u30b9\u30c8p.114\u306b\u63b2\u8f09\u3002 Member.c \u306f\u3001\u30c6\u30ad\u30b9\u30c8p.115\u306b\u63b2\u8f09\u3002 LinkedList.h \u306f\u3001\u30c6\u30ad\u30b9\u30c8p.337\u306b\u63b2\u8f09\u3002 LinkedList.c LinkedListTest.c M &hellip; <a href=\"https:\/\/kpc2017.satoshis.jp\/?p=1\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u7dda\u5f62\u30ea\u30b9\u30c8&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/kpc2017.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/1"}],"collection":[{"href":"https:\/\/kpc2017.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kpc2017.satoshis.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kpc2017.satoshis.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kpc2017.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1"}],"version-history":[{"count":8,"href":"https:\/\/kpc2017.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":30,"href":"https:\/\/kpc2017.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions\/30"}],"wp:attachment":[{"href":"https:\/\/kpc2017.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kpc2017.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kpc2017.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}