{"id":373,"date":"2024-04-22T16:08:48","date_gmt":"2024-04-22T08:08:48","guid":{"rendered":"https:\/\/www.sxr666.cn\/?p=373"},"modified":"2024-07-23T20:18:36","modified_gmt":"2024-07-23T12:18:36","slug":"sjjgpta20232","status":"publish","type":"post","link":"https:\/\/www.sxr666.cn\/index.php\/2024\/04\/22\/sjjgpta20232\/","title":{"rendered":"PTA\u6570\u636e\u7ed3\u6784\u4e0e\u7a0b\u5e8f\u8bbe\u8ba1\uff08\u4e0b\uff092023\u7ec3\u4e60"},"content":{"rendered":"\n<p class=\"has-accent-1-color has-text-color has-link-color has-normal-font-size wp-elements-3aa7d499b164f443f4f2d216831a3124\">\u6ce8\u610f\uff1a\u672c\u9875\u9762\u4e2d\u5927\u90e8\u5206\u4ee3\u7801\u90fd\u662f\u7528C++\u7f16\u5199\uff0c\u5728\u63d0\u4ea4\u65f6\u5c3d\u91cf\u5c06\u6240\u6709\u7684\u4ee3\u7801\u7684\u63d0\u4ea4\u65b9\u5f0f\u90fd\u6539\u4e3aC++\uff0c\u5426\u5219\u63d0\u4ea4\u65f6\u4f1a\u62a5\u9519\u3002<\/p>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-1&nbsp;\u987a\u5e8f\u8868\u7684\u63d2\u5165<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-5909f431006d1396b826bb017a91da39\"><code>void insert(int a&#91;],int*n,int x)\n{\n    int i,t;\n    for(i=*n-1;i&gt;=0;i--)\n    {\n        if(x&gt;=a&#91;i])\n        {\n        a&#91;i+1]=x;\n        break;\n    }\n    else\n    {\n        t=a&#91;i];\n        a&#91;i]=x;\n        a&#91;i+1]=t;\n    }\n}\n(*n)++;}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-2&nbsp;\u987a\u5e8f\u8868\u7684\u5220\u9664<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-9e7c6db27b73c20f1128782ab3d5760d\"><code>int del(int a&#91;], int *n, int x) {  \n    int i;  \n    for (i = 0; i &lt; *n; i++) {  \n        if (a&#91;i] == x) {  \n            \/\/ \u4ece\u5f53\u524d\u4f4d\u7f6e\u5f00\u59cb\uff0c\u5c06\u540e\u9762\u7684\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d  \n            for (; i &lt; *n - 1; i++) {  \n                a&#91;i] = a&#91;i + 1];  \n            }  \n            \/\/ \u66f4\u65b0\u6570\u7ec4\u957f\u5ea6  \n            (*n)--;  \n            return 1; \/\/ \u627e\u5230\u4e86\u5e76\u5220\u9664\u4e86\u5143\u7d20\uff0c\u8fd4\u56de1  \n        }  \n    }  \n    return 0; \/\/ \u6ca1\u6709\u627e\u5230\u5143\u7d20\uff0c\u8fd4\u56de0  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-3&nbsp;\u6784\u9020\u6709\u5e8f\u987a\u5e8f\u8868<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-baaa674224b34274db4d613f950ed506\"><code>void readArray(int a&#91;], int n) {  \n    for (int i = 0; i &lt; n; i++) {  \n        scanf(\"%d\", &amp;a&#91;i]);  \n    }  \n}  \n  \n\/\/ \u51fd\u6570\u7528\u4e8e\u5bf9\u6574\u6570\u6570\u7ec4\u8fdb\u884c\u964d\u5e8f\u6392\u5e8f\uff08\u5192\u6ce1\u6392\u5e8f\uff09  \nvoid bubbleSortDescending(int a&#91;], int n) {  \n    int temp;  \n    int swapped;  \n    for (int i = 0; i &lt; n - 1; i++) {  \n        swapped = 0; \/\/ \u6807\u8bb0\u8fd9\u4e00\u8f6e\u662f\u5426\u6709\u4ea4\u6362\u53d1\u751f  \n        for (int j = 0; j &lt; n - i - 1; j++) { \/\/ \u53ea\u9700\u6bd4\u8f83\u5230\u672a\u6392\u5e8f\u90e8\u5206\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20  \n            if (a&#91;j] &gt; a&#91;j + 1]) {  \n                temp = a&#91;j];  \n                a&#91;j] = a&#91;j + 1];  \n                a&#91;j + 1] = temp;  \n                swapped = 1; \/\/ \u53d1\u751f\u4e86\u4ea4\u6362  \n            }  \n        }  \n        if (!swapped) {  \n            break; \/\/ \u5982\u679c\u6ca1\u6709\u4ea4\u6362\u53d1\u751f\uff0c\u8bf4\u660e\u6570\u7ec4\u5df2\u7ecf\u6392\u5e8f\u5b8c\u6210  \n        }  \n    }  \n}  \n  \n\/\/ \u4e3b\u5904\u7406\u51fd\u6570\uff0c\u73b0\u5728\u53ea\u8d1f\u8d23\u8c03\u7528\u4e0a\u9762\u4e24\u4e2a\u51fd\u6570  \nvoid process(int a&#91;], int n) {  \n    readArray(a, n);  \n    bubbleSortDescending(a, n);  \n    \/\/ \u8fd9\u91cc\u53ef\u4ee5\u6dfb\u52a0\u4ee3\u7801\u4ee5\u8f93\u51fa\u6392\u5e8f\u540e\u7684\u6570\u7ec4\u6216\u5176\u4ed6\u540e\u7eed\u5904\u7406  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-4&nbsp;\u5feb\u901f\u6c42\u6700\u5927\u6700\u5c0f\u503c\uff08\u5206\u6cbb\u6cd5\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-6b6e0e041cc383219e1338aff89bfae6\"><code>int find_extreme(int *a, int m, int n, int (*compare)(int, int)) {\n    if (m == n) return a&#91;m]; \/\/ \u53ea\u6709\u4e00\u4e2a\u5143\u7d20\u65f6\u76f4\u63a5\u8fd4\u56de  \n    \n    int mid = (m + n) \/ 2;  \n    \n    int left = find_extreme(a, m, mid, compare);  \n    int right = find_extreme(a, mid + 1, n, compare);  \n    \n    return compare(left, right) ? right : left;  \n}\n\/\/ \u6bd4\u8f83\u51fd\u6570\nint greater_than(int a, int b) {\n    return a &gt; b;\n}\n\nint less_than(int a, int b) {\n    return a &lt; b;\n}\nint max(int *a, int m, int n) {\n    return find_extreme(a, m, n, &amp;less_than);\n}\n\nint min(int *a, int m, int n) {\n    return find_extreme(a, m, n, &amp;greater_than);\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-5&nbsp;\u6700\u5927\u5b50\u6bb5\u548c\uff08\u5206\u6cbb\u6cd5\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-bdb275e85730bf87174831e40250c78c\"><code>int maxsubsum(int *a,int left,int right){\n    int sum=a&#91;0],maxx=a&#91;0];for(left=1;left&lt;=right;left++){sum=sum&gt;0?sum:0;sum+=a&#91;left];maxx=maxx&gt;sum?maxx:sum;}return maxx;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong><strong>6-6 \u68cb\u76d8\u8986\u76d6\u95ee\u9898\uff08\u5206\u6cbb\u6cd5\uff09<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-364b6888a2ed14d747e01d2eb6c81323\"><code>void ChessBoard(int tr, int tc, int dr, int dc, int size){\n    int sxr,ssr;\n    if(size==1) return;\/\/\u8df3\u51fa\u5faa\u73af\n    sxr=++num;\n    ssr=size\/2;\n    \n    if(dr&lt;(tr+ssr)&amp;&amp;dc&lt;(tc+ssr)){\/\/\u5728\u5de6\u4e0a\u89d2\n        ChessBoard(tr,tc,dr,dc,ssr);\n    }\n    else{\n        board&#91;tr+ssr-1]&#91;tc+ssr-1]=sxr;\n        ChessBoard(tr,tc,tr+ssr-1,tc+ssr-1,ssr);\n    }\n    \n    if(dr&lt;(tr+ssr)&amp;&amp;dc&gt;=(tc+ssr)){\/\/\u5728\u53f3\u4e0a\u89d2\n        ChessBoard(tr,tc+ssr,dr,dc,ssr);\n    }\n    else{\n        board&#91;tr+ssr-1]&#91;tc+ssr]=sxr;\n        ChessBoard(tr,tc+ssr,tr+ssr-1,tc+ssr,ssr);\n    }\n    \n    if(dr&gt;=(tr+ssr)&amp;&amp;dc&lt;(tc+ssr)){\/\/\u5728\u5de6\u4e0b\u89d2\n        ChessBoard(tr+ssr,tc,dr,dc,ssr);\n    }\n    else{\n        board&#91;tr+ssr]&#91;tc+ssr-1]=sxr;\n        ChessBoard(tr+ssr,tc,tr+ssr,tc+ssr-1,ssr);\n    }\n\n    if(dr&gt;=(tr+ssr)&amp;&amp;dc&gt;=(tc+ssr)){\/\/\u5728\u53f3\u4e0b\u89d2\n        ChessBoard(tr+ssr,tc+ssr,dr,dc,ssr);\n    }\n    else{\n        board&#91;tr+ssr]&#91;tc+ssr]=sxr;\n        ChessBoard(tr+ssr,tc+ssr,tr+ssr,tc+ssr,ssr);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-7&nbsp;\u4e24\u4f4d\u6570\u5408\u5e76<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-6981ea02ee94e94769b73f7ed32435aa\"><code>void swap(int a, int b, int *c) {  \n    \/\/ \u786e\u4fdda\u548cb\u90fd\u662f\u4e24\u4f4d\u6570  \n    if (a &lt; 10 || a &gt; 99 || b &lt; 10 || b &gt; 99) {  \n        \/\/ \u5904\u7406\u9519\u8bef\u60c5\u51b5\uff0c\u4f8b\u5982\u8bbe\u7f6ec\u4e3a\u67d0\u4e2a\u7279\u6b8a\u503c\u6216\u8fd4\u56de\u9519\u8bef\u4ee3\u7801  \n        *c = -1; \/\/ \u793a\u4f8b\uff1a\u5c06c\u8bbe\u7f6e\u4e3a-1\u8868\u793a\u9519\u8bef  \n        return;  \n    }  \n  \n    \/\/ \u63d0\u53d6a\u548cb\u7684\u5341\u4f4d\u6570\u548c\u4e2a\u4f4d\u6570  \n    int tensA = a \/ 10;  \n    int onesA = a % 10;  \n    int tensB = b \/ 10;  \n    int onesB = b % 10;  \n  \n    \/\/ \u91cd\u65b0\u7ec4\u5408\u6570\u5b57\u5e76\u5b58\u50a8\u5728c\u6307\u5411\u7684\u4f4d\u7f6e  \n    *c = 1000 * tensB + 100 * tensA + 10 * onesB + onesA;  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-8 \u7528\u6307\u9488\u64cd\u4f5c\u6570\u7ec4\u8f93\u5165\u8f93\u51fa\u5143\u7d20(\u6307\u9488\u505a\u5f62\u53c2\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-8c9197ec9a47ed9ed58795cad851b40b\"><code>void fun(int *b, int n) {  \n    for (int i = 0; i &lt; n; i++) {  \n        int *temp = b + i; \/\/ \u4f7f\u7528\u4e34\u65f6\u6307\u9488\u6765\u6307\u5411\u5f53\u524d\u8981\u8bfb\u53d6\u6216\u6253\u5370\u7684\u5143\u7d20  \n        scanf(\"%d\", temp); \/\/ \u8bfb\u53d6\u8f93\u5165\u5230\u5f53\u524d\u4f4d\u7f6e  \n        if (i &lt; n - 1) {  \n            printf(\"%d \", *temp); \/\/ \u5982\u679c\u4e0d\u662f\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u6253\u5370\u5e76\u52a0\u4e0a\u7a7a\u683c  \n        } else {  \n            printf(\"%d\", *temp); \/\/ \u5982\u679c\u662f\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u53ea\u6253\u5370\u5143\u7d20\u503c  \n        }  \n    }  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-9 \u7ed3\u6784\u4f53\u6307\u9488\u5f62\u5f0f\u8f93\u51fa<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-2e8166c74ad33975cbde5af1d0f5b813\"><code>void output(RECORD *p, int n) {  \n    while (n--) {  \n        printf(\"%s,%d\\n\", p-&gt;no, p-&gt;score);  \n        p--; \/\/ \u79fb\u52a8\u5230\u524d\u4e00\u4e2a\u5143\u7d20  \n    }  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-10 \u64cd\u4f5c\u6307\u9488\u4e32\u63a5\u4e24\u4e2a\u7ed3\u70b9<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-523cbcfadf02f5777a8effefe1b9a372\"><code>ptr Connect(int x1, int x2) {  \n    \/\/ \u5206\u914d\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684\u5185\u5b58  \n    ptr first = (ptr)malloc(sizeof(snode));  \n    if (first == NULL) {  \n        \/\/ \u5904\u7406\u5185\u5b58\u5206\u914d\u5931\u8d25\u7684\u60c5\u51b5  \n        return NULL;  \n    }  \n      \n    \/\/ \u4e3a\u7b2c\u4e00\u4e2a\u8282\u70b9\u8d4b\u503c  \n    first-&gt;data = x1;  \n      \n    \/\/ \u5206\u914d\u7b2c\u4e8c\u4e2a\u8282\u70b9\u7684\u5185\u5b58\u5e76\u76f4\u63a5\u94fe\u63a5\u5230\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684next  \n    first-&gt;next = (ptr)malloc(sizeof(snode));  \n    if (first-&gt;next == NULL) {  \n        \/\/ \u5982\u679c\u7b2c\u4e8c\u4e2a\u8282\u70b9\u5185\u5b58\u5206\u914d\u5931\u8d25\uff0c\u91ca\u653e\u7b2c\u4e00\u4e2a\u8282\u70b9\u5e76\u8fd4\u56deNULL  \n        free(first);  \n        return NULL;  \n    }  \n      \n    \/\/ \u4e3a\u7b2c\u4e8c\u4e2a\u8282\u70b9\u8d4b\u503c  \n    first-&gt;next-&gt;data = x2;  \n      \n    \/\/ \u8bbe\u7f6e\u7b2c\u4e8c\u4e2a\u8282\u70b9\u7684next\u4e3aNULL\uff0c\u8868\u793a\u94fe\u8868\u7ed3\u675f  \n    first-&gt;next-&gt;next = NULL;  \n      \n    \/\/ \u8fd4\u56de\u94fe\u8868\u7684\u5934\u8282\u70b9  \n    return first;  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-11 \u64cd\u4f5c\u6307\u9488\u5220\u9664\u4e09\u4e2a\u5df2\u4e32\u63a5\u7ed3\u70b9\u4e2d\u7684\u7b2c\u4e8c\u4e2a\u7ed3\u70b9<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-0e3f28321f6810603a3ce0ebf662cef9\"><code>ptr destroy(ptr p1) {  \n    if (p1 != NULL &amp;&amp; p1-&gt;next != NULL) {  \n        ptr to_free = p1-&gt;next;  \n        p1-&gt;next = to_free-&gt;next;  \n        free(to_free);  \n    }  \n    return p1;  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-12 \u8868\u5934\u63d2\u5165\u6cd5\u6784\u9020\u94fe\u8868<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-807daaba15ef96092a2344efccc8d106\"><code>ptr creat() {  \n    ptr head = NULL, p, prev = NULL;  \n    int x;  \n  \n    \/\/ \u8bfb\u53d6\u7b2c\u4e00\u4e2a\u6570\u636e\u9879  \n    scanf(\"%d\", &amp;x);  \n      \n    \/\/ \u5f53\u7528\u6237\u8f93\u5165\u975e0\u503c\u65f6\uff0c\u521b\u5efa\u65b0\u8282\u70b9\u5e76\u6dfb\u52a0\u5230\u94fe\u8868\u4e2d  \n    while (x != 0) {  \n        p = (ptr)malloc(sizeof(snode));  \n        if (p == NULL) {  \n            \/\/ \u5904\u7406\u5185\u5b58\u5206\u914d\u5931\u8d25\u7684\u60c5\u51b5  \n            \/\/ ...  \n            return NULL;  \n        }  \n        p-&gt;data = x;  \n        p-&gt;next = head; \/\/ \u65b0\u8282\u70b9\u6307\u5411\u5f53\u524d\u5934\u8282\u70b9  \n        head = p; \/\/ \u66f4\u65b0\u5934\u8282\u70b9\u4e3a\u65b0\u8282\u70b9  \n        prev = p; \/\/ \u66f4\u65b0prev\u4e3a\u5f53\u524d\u8282\u70b9\uff0c\u4ee5\u4fbf\u5728\u4e0b\u6b21\u5faa\u73af\u4e2d\u5904\u7406  \n        scanf(\"%d\", &amp;x); \/\/ \u8bfb\u53d6\u4e0b\u4e00\u4e2a\u6570\u636e\u9879  \n    }  \n  \n    return head;  \n}\nvoid output(ptr p) {  \n    while (p != NULL) {  \n        printf(\"%d \", p-&gt;data);  \n        p = p-&gt;next; \/\/ \u79fb\u52a8\u5230\u4e0b\u4e00\u4e2a\u8282\u70b9  \n    }  \n    printf(\"\\n\"); \/\/ \u8f93\u51fa\u6362\u884c\u7b26\u4ee5\u6539\u5584\u53ef\u8bfb\u6027  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-13 \u8868\u5c3e\u63d2\u5165\u6cd5\u6784\u9020\u94fe\u8868<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-6608c352c0724f83078e28cdb5ec5063\"><code>ptr creat() {  \n    int x;  \n    ptr head = NULL, last = NULL;  \n  \n    \/\/ \u8bfb\u53d6\u7b2c\u4e00\u4e2a\u5143\u7d20  \n    scanf(\"%d\", &amp;x);  \n  \n    \/\/ \u5982\u679c\u8f93\u5165\u7684\u662f0\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u7a7a\u94fe\u8868  \n    if (x == 0) return head;  \n  \n    \/\/ \u521b\u5efa\u7b2c\u4e00\u4e2a\u8282\u70b9  \n    head = (ptr)malloc(sizeof(snode));  \n    if (head == NULL) {  \n        \/\/ \u5904\u7406\u5185\u5b58\u5206\u914d\u5931\u8d25\u7684\u60c5\u51b5  \n        return NULL;  \n    }  \n    head-&gt;data = x;  \n    head-&gt;next = NULL;  \n    last = head; \/\/ last\u6307\u5411\u94fe\u8868\u7684\u6700\u540e\u4e00\u4e2a\u8282\u70b9  \n  \n    \/\/ \u5faa\u73af\u8bfb\u53d6\u5269\u4f59\u5143\u7d20\uff0c\u5e76\u521b\u5efa\u65b0\u7684\u8282\u70b9  \n    while (1) {  \n        scanf(\"%d\", &amp;x);  \n        if (x == 0) break; \/\/ \u5982\u679c\u8f93\u5165\u7684\u662f0\uff0c\u5219\u7ed3\u675f\u5faa\u73af  \n  \n        \/\/ \u521b\u5efa\u65b0\u8282\u70b9  \n        ptr p = (ptr)malloc(sizeof(snode));  \n        if (p == NULL) {  \n            \/\/ \u5904\u7406\u5185\u5b58\u5206\u914d\u5931\u8d25\u7684\u60c5\u51b5  \n            \/\/ \u91ca\u653e\u5df2\u5206\u914d\u7684\u8282\u70b9\u5185\u5b58\uff08\u6b64\u5904\u9700\u8981\u6dfb\u52a0\u989d\u5916\u7684\u903b\u8f91\u6765\u904d\u5386\u94fe\u8868\u5e76\u91ca\u653e\uff09  \n            return NULL;  \n        }  \n        p-&gt;data = x;  \n        p-&gt;next = NULL;  \n  \n        \/\/ \u5c06\u65b0\u8282\u70b9\u6dfb\u52a0\u5230\u94fe\u8868\u7684\u672b\u5c3e  \n        last-&gt;next = p;  \n        last = p; \/\/ \u66f4\u65b0last\u6307\u9488  \n    }  \n  \n    return head;  \n}\nvoid output(ptr p) {  \n    while (p != NULL) {  \n        printf(\"%d \", p-&gt;data);  \n        p = p-&gt;next; \/\/ \u79fb\u52a8\u5230\u4e0b\u4e00\u4e2a\u8282\u70b9  \n    }  \n    printf(\"\\n\"); \/\/ \u8f93\u51fa\u6362\u884c\u7b26\u4ee5\u6539\u5584\u53ef\u8bfb\u6027  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-14 \u5bfb\u627e\u94fe\u8868\u5143\u7d20\u7684\u524d\u9a71\u7ed3\u70b9<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-869db93986e13331f107c47626a260bb\"><code>ptr pre(ptr h, int x) {  \n    ptr current = h, prev = NULL;  \n  \n    \/\/ \u904d\u5386\u94fe\u8868\uff0c\u76f4\u5230\u627e\u5230\u503c\u4e3ax\u7684\u8282\u70b9\u6216\u5230\u8fbe\u94fe\u8868\u672b\u5c3e  \n    while (current != NULL &amp;&amp; current-&gt;data != x) {  \n        prev = current;  \n        current = current-&gt;next;  \n    }  \n  \n    \/\/ \u5982\u679c\u627e\u5230\u4e86\u503c\u4e3ax\u7684\u8282\u70b9\uff0c\u5219\u8fd4\u56de\u5b83\u7684\u524d\u4e00\u4e2a\u8282\u70b9\uff1b\u5426\u5219\u8fd4\u56deNULL  \n    if (current != NULL &amp;&amp; current-&gt;data == x) {  \n        return prev;  \n    }  \n      \n    return NULL;  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-15 \u6c42\u94fe\u8868\u7684\u5012\u6570\u7b2cm\u4e2a\u5143\u7d20<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-9008dfe6c7ab25c1297ade5398a57876\"><code>ElementType Find(List L, int m) {  \n    struct Node *current;  \n    int count = 0;  \n  \n    \/\/ \u7b2c\u4e00\u6b21\u904d\u5386\uff0c\u8ba1\u7b97\u94fe\u8868\u957f\u5ea6\uff0c\u540c\u65f6\u68c0\u67e5\u662f\u5426\u5c0f\u4e8em  \n    current = L-&gt;Next;  \n    while (current != NULL) {  \n        count++;  \n        if (count &lt; m) {  \n            current = current-&gt;Next;  \n        } else {  \n            break; \/\/ \u5982\u679c\u94fe\u8868\u957f\u5ea6\u5927\u4e8e\u6216\u7b49\u4e8em\uff0c\u5219\u9000\u51fa\u5faa\u73af  \n        }  \n    }  \n  \n    \/\/ \u5982\u679c\u94fe\u8868\u957f\u5ea6\u5c0f\u4e8em\uff0c\u5219\u8fd4\u56de\u9519\u8bef  \n    if (count &lt; m) {  \n        return ERROR;  \n    }  \n  \n    \/\/ \u7b2c\u4e8c\u6b21\u904d\u5386\uff0c\u627e\u5230\u7b2cm\u4e2a\u8282\u70b9\u7684\u6570\u636e  \n    current = L-&gt;Next;  \n    for (int i = 0; i &lt; m - 1; i++) { \/\/ \u6ce8\u610f\u8fd9\u91cc\u53ea\u9700\u8981\u904d\u5386\u5230\u7b2cm-1\u4e2a\u8282\u70b9  \n        current = current-&gt;Next;  \n    }  \n  \n    \/\/ \u8fd4\u56de\u7b2cm\u4e2a\u8282\u70b9\u7684\u6570\u636e  \n    return current-&gt;Data;  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-16 \u6784\u9020\u6709\u5e8f\u94fe\u8868<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-61be3b5fffb270bbb049a26003f7ce1a\"><code>ptr creat() {  \n    ptr head = NULL;  \/\/ \u94fe\u8868\u7684\u5934\u6307\u9488  \n    ptr tail = NULL;  \/\/ \u94fe\u8868\u7684\u5c3e\u6307\u9488  \n    ptr newNode;      \/\/ \u65b0\u8282\u70b9\u7684\u6307\u9488  \n    int value;  \n  \n    \/\/ \u5faa\u73af\u8bfb\u53d6\u7528\u6237\u8f93\u5165\uff0c\u76f4\u5230\u8f93\u51650  \n    while (1) {  \n        scanf(\"%d\", &amp;value);  \n        if (value == 0) {  \n            break;  \n        }  \n  \n        \/\/ \u521b\u5efa\u65b0\u8282\u70b9  \n        newNode = (ptr)malloc(sizeof(snode));  \n        newNode->data = value;  \n        newNode->next = NULL;  \n  \n        \/\/ \u63d2\u5165\u65b0\u8282\u70b9\u5230\u6709\u5e8f\u94fe\u8868\u4e2d  \n        if (head == NULL || value &lt;= head->data) {  \n            \/\/ \u65b0\u8282\u70b9\u6210\u4e3a\u65b0\u7684\u5934\u8282\u70b9\u6216\u63d2\u5165\u5230\u5934\u90e8  \n            newNode->next = head;  \n            head = newNode;  \n            if (tail == NULL) {  \n                tail = newNode;  \n            }  \n        } else {  \n            \/\/ \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e  \n            ptr current = head;  \n            while (current->next != NULL &amp;&amp; current->next->data &lt; value) {  \n                current = current->next;  \n            }  \n            \/\/ \u63d2\u5165\u65b0\u8282\u70b9  \n            newNode->next = current->next;  \n            current->next = newNode;  \n            \/\/ \u66f4\u65b0\u5c3e\u6307\u9488\uff0c\u5982\u679c\u5fc5\u8981  \n            if (current == tail) {  \n                tail = newNode;  \n            }  \n        }  \n    }  \n  \n    return head;  \n}  \n  \n\/\/ \u8f93\u51fa\u94fe\u8868\u5143\u7d20  \nvoid output(ptr p) {  \n    ptr current = p;  \n    while (current != NULL) {  \n        printf(\"%d \", current->data);  \n        current = current->next;  \n    }  \n    printf(\"\\n\");  \n} <\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-17 \u52a0\u5934\u94fe\u8868\u7684\u63d2\u5165\u548c\u5220\u9664<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-d1b057ebd9eb6a197f9e04e44d8a892b\"><code>void ins(ptr h,int x){\n    ptr newNode,a,b;\n    newNode=(ptr)malloc(sizeof(snode));\n    newNode->data=x;\n    ptr sxr = h;  \n    \n    while (sxr->next != NULL &amp;&amp; sxr->next->data &lt; x) {  \n        sxr = sxr->next;  \n    }  \n    \/\/ \u63d2\u5165\u65b0\u8282\u70b9  \n    newNode->next = sxr->next;  \n    sxr->next = newNode;  \n    return;\n}\n\nvoid del(ptr h, int x){\n    ptr sxr = h, prev = NULL;  \n    while(sxr != NULL &amp;&amp; sxr->data != x){  \n        prev = sxr; \/\/ \u4fdd\u5b58\u5f53\u524d\u8282\u70b9\u7684\u4e0a\u4e00\u4e2a\u8282\u70b9  \n        sxr = sxr->next;  \n    }  \n    if(sxr == NULL){  \n        printf(\"no %d\\n\", x);  \n        return;  \n    }  \n    if(prev == NULL){ \/\/ \u5982\u679c\u8981\u5220\u9664\u7684\u8282\u70b9\u662f\u5934\u8282\u70b9  \n        h = sxr->next;  \n    } else {  \n        prev->next = sxr->next; \/\/ \u5426\u5219\u66f4\u65b0\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684 next \u6307\u9488  \n    }  \n    free(sxr); \/\/ \u91ca\u653e\u88ab\u5220\u9664\u8282\u70b9\u7684\u5185\u5b58  \n    return;  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-18 \u5faa\u73af\u5355\u94fe\u8868\u7684\u8ffd\u52a0<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-744e93b5b92f601fc5e548fec68913e2\"><code>void AppendP(struct Node **rear,struct Node *p){\n    if((*rear)==NULL){\n        p->next=p;\n        (*rear)=p;\n    }\n    else{\n        p->next=(*rear)->next;\n        (*rear)->next=p;\n        (*rear)=p;\n    }\n    return;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-19 \u5faa\u73af\u53cc\u94fe\u8868\u63d2\u5165\u64cd\u4f5c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-c86f2b9fe2131f418132593151939963\"><code>Status ListInsert_DuL(DuLinkList &amp;L, int i, ElemType e){\n    DuLinkList sxr=L;\n    DuLinkList rxs;\n    rxs=(DuLinkList)malloc(sizeof(DuLNode));\n    rxs->data=e;\n    for(int j=0;j&lt;i-1;j++){\n        sxr=sxr->next;\n    }\n    rxs->next=sxr->next;\n    sxr->next->prior=rxs;\n    sxr->next=rxs;\n    rxs->prior=sxr;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-20 \u5faa\u73af\u53cc\u94fe\u8868\u5220\u9664\u64cd\u4f5c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-43eb4906cd65f9303d4f2701bab1e471\"><code>int ListDelete_DuL(DuLinkList &amp;L, int i){\n    DuLinkList sxr=L,rxs,rsx;\n    for(int j=0;j&lt;i-1;j++){\n        sxr=sxr->next;\n    }\n    rsx=sxr->next;\n    sxr->next=rsx->next;\n    rsx->prior=sxr;\n    free(rsx);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-21 \u521b\u5efa\u5faa\u73af\u53cc\u94fe\u8868<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-e15f1097a1754fbd9979ae49fceb0f14\"><code>void CreateDuList(DuLinkList &amp;L,int n){\n    L=(DuLinkList)malloc(sizeof(DuLNode));\n    L->prior=L;\n    L->next=L;\n    DuLinkList p,en=L;\n    for(int i=0;i&lt;n;i++){\n        p=(DuLinkList)malloc(sizeof(DuLNode));\n        cin>>p->data;\n        p->prior=en;\n        p->next=L;\n        en->next=p;\n        en=en->next;\n        L->prior=en;\n    }\n    return;\n\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-22 \u6709\u5e8f\u7a00\u758f\u591a\u9879\u5f0f\u6c42\u548c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-07477d4cab17c65ac845cdddf0f31aa9\"><code>ptr add(ptr ha,ptr hb){\n    ptr h,h1=ha->next,h2=hb->next,p,end;\n    h=malloc(sizeof(node));\n    end=h;\n    while(h1!=NULL&amp;&amp;h2!=NULL){\n        p=malloc(sizeof(node));\n        if(h1->exp&lt;h2->exp){\n            p->ceof=h1->ceof;\n            p->exp=h1->exp;\n            p->next=NULL;\n            h1=h1->next;\n            end->next=p;\n            end=p;\n        }\n        else if(h1->exp>h2->exp){\n            p->ceof=h2->ceof;\n            p->exp=h2->exp;\n            p->next=NULL;\n            h2=h2->next;\n            end->next=p;\n            end=p;\n        }\n        else{\n            if((h1->ceof+h2->ceof)!=0){\n                p->ceof=h1->ceof+h2->ceof;\n                p->exp=h1->exp;\n                p->next=NULL;\n                h1=h1->next;\n                h2=h2->next;\n                end->next=p;\n                end=p;\n            }\n            else{\n                h1=h1->next;\n                h2=h2->next;\n            }\n        }\n    }\n    while(h1!=NULL){\n        p=malloc(sizeof(node));\n        p->ceof=h1->ceof;\n        p->exp=h1->exp;\n        p->next=NULL;\n        h1=h1->next;\n        end->next=p;\n        end=p;\n    }\n    while(h2!=NULL){\n        p=malloc(sizeof(node));\n        p->ceof=h2->ceof;\n        p->exp=h2->exp;\n        p->next=NULL;\n        h2=h2->next;\n        end->next=p;\n        end=p;\n    }\n    return h;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-23 \u7b80\u5355\u8868\u8fbe\u5f0f\u6c42\u503c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-2497110ce62d682cb1fac105c377c0f3\"><code>int cal( char a&#91;] )\n{\n    int i=0,x=0,z=0,s;\n    char sxr;\n    while(a&#91;i]!='=')\n    {\n        while(a&#91;i]>='0'&amp;&amp;a&#91;i]&lt;='9')\n        {\n            x=x*10+a&#91;i]-'0';\n            i++;\n        }\n        sxr=a&#91;i++];\n        while(a&#91;i]>='0'&amp;&amp;a&#91;i]&lt;='9')\n        {\n            z=z*10+a&#91;i]-'0';\n            i++;\n        }\n    }\n    switch(sxr)\n    {\n        case '+':s=x+z;break;\n        case '-':s=x-z;break;\n        case '*':s=x*z;break;\n        case '\/':s=x\/z;\n    }\n    return s;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-24 \u62ec\u53f7\u5339\u914d\u5224\u65ad<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-0916c9f373868e5c538fd02643a199e1\"><code>typedef struct {  \n    char data&#91;1000];  \n    int top;  \n} Stack;  \n  \n\/\/ \u521d\u59cb\u5316\u6808  \nvoid initStack(Stack *s) {  \n    s->top = -1;  \n}  \n  \n\/\/ \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a  \nint isEmpty(Stack *s) {  \n    return s->top == -1;  \n}  \n  \n\/\/ \u5165\u6808  \nvoid push(Stack *s, char item) {  \n    if (s->top &lt; 999) {  \n        s->data&#91;++s->top] = item;  \n    } else {  \n        printf(\"Stack is full\\n\");  \n        exit(1);  \n    }  \n}  \n  \n\/\/ \u51fa\u6808  \nchar pop(Stack *s) {  \n    if (!isEmpty(s)) {  \n        return s->data&#91;s->top--];  \n    } else {  \n        printf(\"Stack is empty\\n\");  \n        exit(1);  \n    }  \n}  \n  \n\/\/ \u68c0\u67e5\u6808\u9876\u5143\u7d20  \nchar peek(Stack *s) {  \n    if (!isEmpty(s)) {  \n        return s->data&#91;s->top];  \n    } else {  \n        printf(\"Stack is empty\\n\");  \n        exit(1);  \n    }  \n}  \n  \n\/\/ \u5339\u914d\u51fd\u6570  \nint match(char *exp) {  \n    Stack s;  \n    initStack(&amp;s);  \n    char *p = exp;  \n    while (*p) {  \n        switch (*p) {  \n            case '(':  \n            case '&#91;':  \n            case '{':  \n                push(&amp;s, *p);  \n                break;  \n            case ')':  \n                if (!isEmpty(&amp;s) &amp;&amp; peek(&amp;s) == '(') {  \n                    pop(&amp;s);  \n                } else {  \n                    return 0; \/\/ \u4e0d\u5339\u914d  \n                }  \n                break;  \n            case ']':  \n                if (!isEmpty(&amp;s) &amp;&amp; peek(&amp;s) == '&#91;') {  \n                    pop(&amp;s);  \n                } else {  \n                    return 0; \/\/ \u4e0d\u5339\u914d  \n                }  \n                break;  \n            case '}':  \n                if (!isEmpty(&amp;s) &amp;&amp; peek(&amp;s) == '{') {  \n                    pop(&amp;s);  \n                } else {  \n                    return 0; \/\/ \u4e0d\u5339\u914d  \n                }  \n                break;  \n            default:  \n                \/\/ \u5982\u679c\u662f\u5176\u4ed6\u5b57\u7b26\uff0c\u5219\u7ee7\u7eed\u68c0\u67e5\u4e0b\u4e00\u4e2a\u5b57\u7b26  \n                break;  \n        }  \n        p++;  \n    }  \n    return isEmpty(&amp;s); \/\/ \u5982\u679c\u6808\u4e3a\u7a7a\uff0c\u8bf4\u660e\u6240\u6709\u62ec\u53f7\u90fd\u5339\u914d\uff0c\u8fd4\u56de1\uff1b\u5426\u5219\u8fd4\u56de0  \n} <\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-25 \u8868\u8fbe\u5f0f\u6c42\u503c-\u6df7\u5408\u56db\u5219\u8fd0\u7b97<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-43e390e74bf97b3dca2a316bf14c8dea\"><code>int order(char a, char b)\n{\n int ar=0,br=0;\n if(a=='*'||a=='\/') ar=2;\n else \n     if(a=='+'||a=='-') ar=1;\n if(b=='*'||b=='\/') br=2;\n else \n     if(b=='+'||b=='-') br=1;\n if(b=='=')br=-1;\n if(ar>=br) return 1;\n else return 0;\n}\ndouble calcu(double a, double b ,char c)\n{\n switch(c)\n {\n  case '+':return a+b;\n  case '-':return a-b;\n  case '*':return a*b;\n  case '\/':return a\/b;\n }\n return 0;\n}\n\nvoid insta(char str&#91;],double nust&#91;],char opst&#91;])\n{\n int m=0, n=0,i=0;\n double tenu=0;\n for(;str&#91;i]!='\\0';i++)\n {\n  if(str&#91;i]&lt;='9'&amp;&amp;str&#91;i]>='0')\n   tenu=tenu*10+str&#91;i]-'0';\n  else\n      if(str&#91;i]=='+'||str&#91;i]=='-'||str&#91;i]=='*'||str&#91;i]=='\/'||str&#91;i]=='('||str&#91;i]==')'||str&#91;i]=='=')\n      {\n       nust&#91;m++]=tenu;\n       tenu=0;\n       opst&#91;n++]=str&#91;i];\n      }\n }\n}\n\nint cal(char str&#91;])\n{\n    double nust&#91;20];\n    char opst&#91;20];\n insta(str,nust,opst);\n while(opst&#91;0]!='=')\n {\n  int i=0;\n  if(order(opst&#91;i],opst&#91;i+1]))\n  {\n   double a=calcu(nust&#91;i],nust&#91;i+1],opst&#91;i]);\n   nust&#91;i]=a;\n   for(int w=i+1;nust&#91;w]!=0;w++)\n    nust&#91;w]=nust&#91;w+1];\n   for(int w=i;opst&#91;w]!='\\0';w++)\n    opst&#91;w]=opst&#91;w+1];\n  }\n  else\n  {\n   i++;\n   double a=calcu(nust&#91;i],nust&#91;i+1],opst&#91;i]);\n   nust&#91;i]=a;\n   for(int w=i+1;nust&#91;w]!=0;w++)\n    nust&#91;w]=nust&#91;w+1];\n   for(int w=i;opst&#91;w]!='\\0';w++)\n    opst&#91;w]=opst&#91;w+1];\n  }\n }\n    return nust&#91;0];\n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-26 \u77e9\u9635\u8f6c\u7a00\u758f\u77e9\u9635<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-7d0ad7200ea1b441113767d546c58178\"><code>int create_mat(int (*d)&#91;N],int m,int n,elem *a){\n    int i,j,k=0;\n    for(i=0;i&lt;m;i++){\n        for(j=0;j&lt;n;j++){\n            if(d&#91;i]&#91;j]!=0){\n                a&#91;k].row=i;\n                a&#91;k].col=j;\n                a&#91;k].val=d&#91;i]&#91;j];\n                k++;\n            }\n        }\n    }\n    return k;\n}\n\nvoid show_mat(elem *a,int n){\n    int i;\n    for(i=0;i&lt;n;i++){\n        printf(\"%d %d %d\\n\",a&#91;i].row,a&#91;i].col,a&#91;i].val);\n    }\n    return;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-27 \u7a00\u758f\u77e9\u9635\u8f6c\u7f6e<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-361aa91a34eb60c916a164fa02d9201e\"><code>void trans_mat(elem a&#91;],int n,elem b&#91;]){\n    int i,k=0;\n    for(i=0;i&lt;n;i++){\n        b&#91;k].row=a&#91;i].col;\n        b&#91;k].col=a&#91;i].row;\n        b&#91;k].val=a&#91;i].val;\n        k++;\n    }\n    return;\n}\n\nvoid show_mat(elem a&#91;],int n){\n    int i,j,sxr&#91;6]&#91;6]={0};\n    for(i=0;i&lt;n;i++){\n        sxr&#91;a&#91;i].row]&#91;a&#91;i].col]=a&#91;i].val;\n    }\n    for(i=0;i&lt;N;i++){\n        for(j=0;j&lt;N;j++){\n            if(sxr&#91;i]&#91;j]!=0){\n                printf(\"%d %d %d\\n\",i,j,sxr&#91;i]&#91;j]);\n            }\n        }\n    }\n    return;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-28 \u7a00\u758f\u77e9\u9635\u6c42\u548c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-666470b0ae06ce3c25d19f418f60669a\"><code>int add_mat(elem a&#91;],int t1,elem b&#91;],int t2, elem c&#91;]){\n    int i,j,k=0,sxr&#91;M]&#91;N]={0},s;\n    for(i=0;i&lt;t1;i++){\n        for(j=0;j&lt;t2;j++){\n            if(a&#91;i].row==b&#91;j].row&amp;&amp;a&#91;i].col==b&#91;j].col&amp;&amp;(a&#91;i].val+b&#91;j].val)!=0){\n                sxr&#91;a&#91;i].row]&#91;a&#91;i].col]=a&#91;i].val+b&#91;j].val;\n            }\n        }\n    }\n    for(i=0;i&lt;t1;i++){\n        for(j=0;j&lt;t2;j++){\n            if(a&#91;i].row==b&#91;j].row&amp;&amp;a&#91;i].col==b&#91;j].col){\n                j=999;\n            }\n        }\n        if(j==t2){\n            sxr&#91;a&#91;i].row]&#91;a&#91;i].col]=a&#91;i].val;\n        }\n    }\n    \n    for(j=0;j&lt;t2;j++){\n        for(i=0;i&lt;t1;i++){\n            if(a&#91;i].row==b&#91;j].row&amp;&amp;a&#91;i].col==b&#91;j].col){\n                i=999;\n            }\n        }\n        if(i==t1){\n            sxr&#91;b&#91;j].row]&#91;b&#91;j].col]=b&#91;j].val;\n        }\n    }\n    for(i=0;i&lt;M;i++){\n        for(j=0;j&lt;N;j++){\n            if(sxr&#91;i]&#91;j]!=0){\n                c&#91;k].row=i;\n                c&#91;k].col=j;\n                c&#91;k].val=sxr&#91;i]&#91;j];\n                k++;\n            }\n        }\n    }\n    return k;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-29 \u4e8c\u53c9\u6811\u7684\u904d\u5386<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-5c06e9ad14af7d2c3ae1795eafc35484\"><code>Bptr creat(){\n    Bptr a,b,c;\n    a=(Bptr)malloc(sizeof(Bnode));\n    b=(Bptr)malloc(sizeof(Bnode));\n    c=(Bptr)malloc(sizeof(Bnode));\n    scanf(\"%d%d%d\",&amp;a->data,&amp;b->data,&amp;c->data);\n    a->Lson=b;\n    a->Rson=c;\n    b->Lson=NULL;\n    b->Rson=NULL;\n    c->Lson=NULL;\n    c->Rson=NULL;\n    return a;\n}\nvoid preorder(Bptr p){\n    printf(\"%d \",p->data);\n    printf(\"%d \",p->Lson->data);\n    printf(\"%d \",p->Rson->data);\n    return;\n}\nvoid inorder(Bptr p){\n    printf(\"%d \",p->Lson->data);\n    printf(\"%d \",p->data);\n    printf(\"%d \",p->Rson->data);\n    return;\n}\nvoid postorder(Bptr p){\n    printf(\"%d \",p->Lson->data);\n    printf(\"%d \",p->Rson->data);\n    printf(\"%d \",p->data);\n    return;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>6-30 \u8ba1\u7b97\u4e8c\u53c9\u6811\u7684\u53f6\u5b50\u6570<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-26861d5cd4028a955c946587e1172e28\"><code>int num(Bptr p) {  \n    if (p == NULL) {  \n        \/\/ \u5982\u679c\u8282\u70b9\u4e3a\u7a7a\uff08\u5230\u8fbe\u53f6\u5b50\u7684\u4e0b\u65b9\uff09\uff0c\u5219\u8fd4\u56de0  \n        return 0;  \n    }  \n    if (p->Lson == NULL &amp;&amp; p->Rson == NULL) {  \n        \/\/ \u5982\u679c\u8282\u70b9\u662f\u53f6\u5b50\u8282\u70b9\uff08\u6ca1\u6709\u5de6\u53f3\u5b50\u8282\u70b9\uff09\uff0c\u5219\u8fd4\u56de1  \n        return 1;  \n    }  \n    \/\/ \u5426\u5219\uff0c\u9012\u5f52\u5730\u8ba1\u7b97\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u7684\u53f6\u5b50\u8282\u70b9\u6570\uff0c\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u548c  \n    return num(p->Lson) + num(p->Rson);  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-1 \u6808\u7684\u57fa\u672c\u64cd\u4f5c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-10d52479259abc25a7e2906546d93a76\"><code>#include &lt;stack>\n#include &lt;iostream>\nusing namespace std;\nint main(){\n    int n,tem;\n    stack &lt;int> sxr;\n    cin>>n;\n    for(int i=0;i&lt;n;i++){\n        cin>>tem;\n        if(tem!=0){\n            if(sxr.size()==10) cout&lt;&lt;\"FULL \";\n            else sxr.push(tem);\n        }\n        else{\n            if(!sxr.empty()){\n                cout&lt;&lt;sxr.top()&lt;&lt;\" \";\n                sxr.pop();\n            }\n            else cout&lt;&lt;\"EMPTY \";\n        }\n    }\n    cout&lt;&lt;endl;\n    while(!sxr.empty()){\n        cout&lt;&lt;sxr.top()&lt;&lt;\" \";\n        sxr.pop();\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-2 Windows\u6d88\u606f\u961f\u5217<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-a896b1256e34370eeae58bcb67220c7d\"><code>#include &lt;bits\/stdc++.h>  \nusing namespace std;  \nstruct Message {  \n    string name;  \n    int priority;  \n    Message(const string&amp; n, int p) : name(n), priority(p) {}  \n    \/\/ \u6bd4\u8f83\u51fd\u6570\uff0c\u7528\u4e8e\u4f18\u5148\u961f\u5217\u7684\u81ea\u5b9a\u4e49\u6392\u5e8f  \n    bool operator&lt;(const Message&amp; other) const {  \n        \/\/ \u6ce8\u610f\u8fd9\u91cc\u7684\u6bd4\u8f83\u662f\u53cd\u7684\uff0c\u56e0\u4e3a\u4f18\u5148\u7ea7\u503c\u8d8a\u5c0f\u4f18\u5148\u7ea7\u8d8a\u9ad8  \n        return priority > other.priority;  \n    }  \n};  \n  \nint main() {  \n    int n;  \n    cin >> n;  \n  \n    priority_queue&lt;Message> msgQueue;  \n  \n    while (n--) {  \n        string command;  \n        cin >> command;  \n  \n        if (command == \"PUT\") {  \n            string msgName;  \n            int priority;  \n            cin >> msgName >> priority;  \n            msgQueue.push(Message(msgName, priority));  \n        } else if (command == \"GET\") {  \n            if (msgQueue.empty()) {  \n                cout &lt;&lt; \"EMPTY QUEUE!\" &lt;&lt; endl;  \n            } else {  \n                Message msg = msgQueue.top();  \n                msgQueue.pop();  \n                cout &lt;&lt; msg.name &lt;&lt; endl;  \n            }  \n        }  \n    }  \n  \n    return 0;  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-3 \u6c42\u89e3\u53f3\u6700\u503c\u95ee\u9898<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-dbd811e2f46a9853f39603e211c15ba4\"><code>#include &lt;iostream>\nusing namespace std;\nint main(void)\n{\n    int n,i,j,a&#91;20],b&#91;20],count=0,flag=0;\n    cin >> n;\n    for(i=0;i&lt;n;i++) cin >>a&#91;i];\n    for(i=0;i&lt;n;i++)\n    {\n        flag=0;\n        for(j=i+1;j&lt;n;j++)\n        {\n            if(a&#91;i]&lt;a&#91;j]) flag++;\n        }\n        if(flag==0)\n        {\n            b&#91;count]=a&#91;i];\n            count++;\n        }\n    }\n    for(i=0;i&lt;count;i++) cout &lt;&lt; b&#91;i] &lt;&lt; \" \";\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-4 \u961f\u7684\u57fa\u672c\u64cd\u4f5c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-aa31e894a29f8ae5139f8d0c674212ac\"><code>\/\/\u6ce8\u610f\uff1a\u8fd9\u91cc\u662f\u91c7\u7528\u5faa\u73af\u961f\u5217\u5b8c\u6210\uff0c\u7981\u7528\u4e00\u4e2a\u7a7a\u95f4\u7684\u65b9\u6cd5\n\/\/\u7981\u7528\u4e00\u4e2a\u7a7a\u95f4\n\n#include &lt;queue>\n#include &lt;iostream>\nusing namespace std;\nint main(){\n    int n,tem;\n    queue &lt;int> sxr;\n    cin>>n;\n    for(int i=0;i&lt;n;i++){\n        cin>>tem;\n        if(tem!=0){\n            if(sxr.size()==9) cout&lt;&lt;\"FULL \";\n            else sxr.push(tem);\n        }\n        else{\n            if(!sxr.empty()){\n                cout&lt;&lt;sxr.front()&lt;&lt;\" \";\n                sxr.pop();\n            }\n            else cout&lt;&lt;\"EMPTY \";\n        }\n    }\n    cout&lt;&lt;endl;\n    while(!sxr.empty()){\n        cout&lt;&lt;sxr.front()&lt;&lt;\" \";\n        sxr.pop();\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-5 \u77e9\u9635A\u4e58\u4ee5B<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-7bd6218f297ca3140ee8ee4db8bfee91\"><code>#include &lt;bits\/stdc++.h>\nusing namespace std;\n\nint main(){\n    int ra,ca,rb,cb,sum=0;\n    int a&#91;100]&#91;100];\n    int b&#91;100]&#91;100];\n    \n    cin>>ra>>ca;\n    for(int i=0;i&lt;ra;i++){\n        for(int j=0;j&lt;ca;j++){\n            cin>>a&#91;i]&#91;j];\n        }\n    }\n    \n    cin>>rb>>cb;\n    for(int i=0;i&lt;rb;i++){\n        for(int j=0;j&lt;cb;j++){\n            cin>>b&#91;i]&#91;j];\n        }\n    }\n    if(ca!=rb) cout&lt;&lt;\"Error: \"&lt;&lt;ca&lt;&lt;\" != \"&lt;&lt;rb;\n    else{\n        cout&lt;&lt;ra&lt;&lt;\" \"&lt;&lt;cb&lt;&lt;endl;\n        for(int i=0;i&lt;ra;i++){\n            for(int j=0;j&lt;cb;j++){\n                sum=0;\n                for(int k=0;k&lt;ca;k++){\n                    sum+=a&#91;i]&#91;k]*b&#91;k]&#91;j];\n                }\n                cout&lt;&lt;sum;\n                if(j!=cb-1) cout&lt;&lt;\" \";\n            }\n            cout&lt;&lt;endl;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-6 \u6784\u9020\u6563\u5217\u8868<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-26b8198bb2cca2dee6d5192fd1eda1b6\"><code>#include &lt;bits\/stdc++.h>\nusing namespace std;\n\nint main(){\n    int n,a&#91;18]={0},data,h;\n    cin>>n;\n    for(int i=0;i&lt;n;i++){\n        cin>>data;\n        h=data%17;\n        if(a&#91;h]==0)\n        {\n            a&#91;h]=data;\n            cout&lt;&lt;data&lt;&lt;\" pos: \"&lt;&lt;h&lt;&lt;endl;\n        }\n        else{\n            while(a&#91;h]!=0){\n                h=(h+5)%18;\n            }\n            a&#91;h]=data;\n            cout&lt;&lt;data&lt;&lt;\" pos: \"&lt;&lt;h&lt;&lt;endl;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-7 \u6563\u5217\u8868\u67e5\u627e<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-0de92179ae7e7e594e9cd5c1fabac2a6\"><code>\/\/\u672c\u9898\u7684\u5751\u70b9\uff1a\u5f53\u60f3\u8981\u67e5\u627e0\u7684\u65f6\u5019\uff0c\u82e5\u8bbe\u7f6e\u7684a&#91;18]\u521d\u59cb\u503c\u4e3a0\uff0c\u5219\u6b64\u65f6\u4f1a\u62a5\u627e\u5230\u4e86\uff0c\u8fd9\u4e0d\u7b26\u5408\u6211\u4eec\u60f3\u8981\u7684\u67e5\u627e\u5b58\u4e0d\u5b58\u57280\n\n\n#include &lt;bits\/stdc++.h>  \nusing namespace std;  \n  \nint main() {  \n    \/\/ \u521d\u59cb\u5316\u6563\u5217\u8868\u6570\u7ec4a\uff0c\u5927\u5c0f\u4e3a18\uff0c\u6240\u6709\u5143\u7d20\u521d\u59cb\u5316\u4e3a0  \n    int a&#91;18];\n    memset(a,-1,sizeof(a));\n    int n, data, cou = 0;  \n  \n    \/\/ \u7b2c\u4e00\u4e2a\u5faa\u73af\uff1a\u63a5\u6536\u6570\u636e\u5e76\u5b58\u50a8\u5230\u6563\u5217\u8868  \n    cin >> n;  \n    for (int i = 0; i &lt; n; i++) {  \n        cin >> data;  \n        int h = data % 17; \/\/ \u8ba1\u7b97\u54c8\u5e0c\u503c  \n        int k = 0;  \n        int hp = h; \/\/ \u521d\u59cb\u4f4d\u7f6e\u4e3a\u54c8\u5e0c\u503c\u5bf9\u5e94\u7684\u4f4d\u7f6e  \n  \n        \/\/ \u67e5\u627e\u7b2c\u4e00\u4e2a\u7a7a\u4f4d\u7f6e\u5b58\u50a8\u6570\u636e  \n        while (a&#91;hp] != -1) {  \n            k++;  \n            hp = (h + k * k) % 18;  \n        }  \n        a&#91;hp] = data; \/\/ \u5c06\u6570\u636e\u5b58\u50a8\u5230\u627e\u5230\u7684\u4f4d\u7f6e  \n        cout &lt;&lt; hp &lt;&lt; \" \"; \/\/ \u8f93\u51fa\u5b58\u50a8\u4f4d\u7f6e  \n    }  \n    cout &lt;&lt; endl; \/\/ \u8f93\u51fa\u6362\u884c  \n  \n    \/\/ \u7b2c\u4e8c\u4e2a\u5faa\u73af\uff1a\u63a5\u6536\u6570\u636e\u5e76\u67e5\u627e\u5728\u6563\u5217\u8868\u4e2d\u7684\u4f4d\u7f6e  \n    cin >> n;  \n    for (int i = 0; i &lt; n; i++) {  \n        cin >> data;  \n        cou = 1; \/\/ \u5c1d\u8bd5\u6b21\u6570\u521d\u59cb\u5316\u4e3a1  \n        int h = data % 17; \/\/ \u8ba1\u7b97\u54c8\u5e0c\u503c  \n        int k = 0;  \n        int hp = h; \/\/ \u521d\u59cb\u4f4d\u7f6e\u4e3a\u54c8\u5e0c\u503c\u5bf9\u5e94\u7684\u4f4d\u7f6e  \n  \n        \/\/ \u67e5\u627e\u6570\u636e\u5728\u6563\u5217\u8868\u4e2d\u7684\u4f4d\u7f6e  \n        while (a&#91;hp] != data &amp;&amp; a&#91;hp] != -1) {  \n            cou++; \/\/ \u5c1d\u8bd5\u6b21\u6570\u52a01  \n            k++;  \n            hp = (h + k * k) % 18; \/\/ \u4f7f\u7528\u54c8\u5e0c\u51fd\u6570\u8ba1\u7b97\u4e0b\u4e00\u4e2a\u53ef\u80fd\u7684\u4f4d\u7f6e  \n        }  \n  \n        \/\/ \u8f93\u51fa\u7ed3\u679c  \n        if (a&#91;hp] == data)  \n            cout &lt;&lt; data &lt;&lt; \" pos:\" &lt;&lt; hp &lt;&lt; \",try \" &lt;&lt; cou &lt;&lt; endl;  \n        else  \n            cout &lt;&lt; data &lt;&lt; \" not found,try \" &lt;&lt; cou &lt;&lt; endl;  \n    }  \n  \n    return 0;  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-8 \u540e\u5e8f\u548c\u4e2d\u5e8f\u6784\u9020\u4e8c\u53c9\u6811<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-73d80f8d8e210c45fceafd6592d7fea9\"><code>#include &lt;iostream>\nusing namespace std;\n\nstruct TreeNode {\n    int val;\n    TreeNode* left;\n    TreeNode* right;\n    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n};\n\n\/\/ \u4f7f\u7528\u540e\u5e8f\u548c\u4e2d\u5e8f\u5e8f\u5217\u6784\u5efa\u4e8c\u53c9\u6811\u7684\u9012\u5f52\u51fd\u6570\nTreeNode* buildTree(int postorder&#91;], int inorder&#91;], int postStart, int postEnd, int inStart, int inEnd) {\n    if (postStart > postEnd) return nullptr;\n    \n    \/\/ \u540e\u5e8f\u5e8f\u5217\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u662f\u6839\u8282\u70b9\n    TreeNode* root = new TreeNode(postorder&#91;postEnd]);\n    int inRootIndex = -1;\n    \/\/ \u5728\u4e2d\u5e8f\u5e8f\u5217\u4e2d\u627e\u5230\u6839\u8282\u70b9\u7684\u7d22\u5f15\n    for (int i = inStart; i &lt;= inEnd; ++i) {\n        if (inorder&#91;i] == root->val) {\n            inRootIndex = i;\n            break;\n        }\n    }\n    \/\/ \u9012\u5f52\u6784\u5efa\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\n    root->left = buildTree(postorder, inorder, postStart, postStart + inRootIndex - inStart - 1, inStart, inRootIndex - 1);\n    root->right = buildTree(postorder, inorder, postStart + inRootIndex - inStart, postEnd - 1, inRootIndex + 1, inEnd);\n    \n    return root;\n}\n\n\/\/ \u5148\u5e8f\u904d\u5386\u4e8c\u53c9\u6811\u5e76\u6253\u5370\nvoid preorderTraversal(TreeNode* root) {\n    if (!root) return;\n    cout &lt;&lt; root->val &lt;&lt; \" \";\n    preorderTraversal(root->left);\n    preorderTraversal(root->right);\n}\n\nint main() {\n    int n;\n    cin >> n;\n    int postorder&#91;10], inorder&#91;10];\n    \n    \/\/ \u8bfb\u53d6\u540e\u5e8f\u5e8f\u5217\n    for (int i = 0; i &lt; n; ++i) cin >> postorder&#91;i];\n    \/\/ \u8bfb\u53d6\u4e2d\u5e8f\u5e8f\u5217\n    for (int i = 0; i &lt; n; ++i) cin >> inorder&#91;i];\n    \n    \/\/ \u6784\u5efa\u4e8c\u53c9\u6811\u5e76\u904d\u5386\n    TreeNode* root = buildTree(postorder, inorder, 0, n - 1, 0, n - 1);\n    preorderTraversal(root);\n    \n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-9 \u5148\u5e8f\u548c\u540e\u5e8f\u6784\u9020\u6b63\u5219\u4e8c\u53c9\u6811<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-67f3ed516fb4df94d43bb03619c2d7b7\"><code>#include &lt;iostream>\n#include &lt;vector>\n#include &lt;unordered_map>\nusing namespace std;\n\nstruct TreeNode {\n    int val;\n    TreeNode *left;\n    TreeNode *right;\n    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n};\n\n\/\/ \u901a\u8fc7\u5148\u5e8f\u5e8f\u5217\u548c\u540e\u5e8f\u5e8f\u5217\u6784\u9020\u6b63\u5219\u4e8c\u53c9\u6811\nTreeNode* buildTree(vector&lt;int>&amp; preorder, vector&lt;int>&amp; postorder, int preStart, int preEnd, int postStart, int postEnd) {\n    if (preStart > preEnd || postStart > postEnd) {\n        return nullptr;\n    }\n\n    TreeNode* root = new TreeNode(preorder&#91;preStart]);\n\n    if (preStart == preEnd) {\n        return root;\n    }\n\n    int leftRootValue = preorder&#91;preStart + 1];\n    int leftRootIndexPost = postStart;\n    while (postorder&#91;leftRootIndexPost] != leftRootValue) {\n        leftRootIndexPost++;\n    }\n\n    int leftSubtreeSize = leftRootIndexPost - postStart + 1;\n\n    root->left = buildTree(preorder, postorder, preStart + 1, preStart + leftSubtreeSize, postStart, leftRootIndexPost);\n    root->right = buildTree(preorder, postorder, preStart + leftSubtreeSize + 1, preEnd, leftRootIndexPost + 1, postEnd - 1);\n\n    return root;\n}\n\n\/\/ \u4e2d\u5e8f\u904d\u5386\uff0c\u83b7\u53d6\u4e2d\u5e8f\u5e8f\u5217\nvoid inorderTraversal(TreeNode* root, vector&lt;int>&amp; inorder) {\n    if (root == nullptr) {\n        return;\n    }\n    inorderTraversal(root->left, inorder);\n    inorder.push_back(root->val);\n    inorderTraversal(root->right, inorder);\n}\n\nint main() {\n    int n;\n    cin >> n;\n\n    vector&lt;int> preorder(n);\n    vector&lt;int> postorder(n);\n\n    for (int i = 0; i &lt; n; ++i) {\n        cin >> preorder&#91;i];\n    }\n\n    for (int i = 0; i &lt; n; ++i) {\n        cin >> postorder&#91;i];\n    }\n\n    \/\/ \u6784\u9020\u4e8c\u53c9\u6811\n    TreeNode* root = buildTree(preorder, postorder, 0, n - 1, 0, n - 1);\n\n    \/\/ \u4e2d\u5e8f\u904d\u5386\u8f93\u51fa\u4e2d\u5e8f\u5e8f\u5217\n    vector&lt;int> inorder;\n    inorderTraversal(root, inorder);\n\n    \/\/ \u8f93\u51fa\u4e2d\u5e8f\u5e8f\u5217\n    for (int i = 0; i &lt; n; ++i) {\n        cout &lt;&lt; inorder&#91;i];\n        if (i &lt; n - 1) {\n            cout &lt;&lt; \" \";\n        } else {\n            cout &lt;&lt; \" \" &lt;&lt; endl;\n        }\n    }\n\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-10 \u6784\u9020\u4e8c\u53c9\u68c0\u7d22\u6811<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-8d2db2148e5552dc0341ef47b4d3f66c\"><code>#include &lt;iostream>  \n  \nusing namespace std;  \n  \nstruct node {  \n    int val;  \n    node *lson, *rson;  \n};  \n  \nvoid app(node*&amp; z, node* x) {  \n    if (z == nullptr) {  \n        z = x;  \n        return;  \n    }  \n    if (x->val &lt;= z->val) {  \n        app(z->lson, x);  \n    } else {  \n        app(z->rson, x);  \n    }  \n}  \n  \nvoid out(node* l) {  \n    if (l == nullptr) {  \n        return;  \n    }  \n    cout &lt;&lt; l->val &lt;&lt; \" \";  \n    out(l->lson);  \n    out(l->rson);  \n}  \n  \nint main() {  \n    int x;  \n    node* root = nullptr;  \n    while (cin >> x &amp;&amp; x != 0) {  \n        node* tem = new node{x, nullptr, nullptr};  \n        app(root, tem);  \n    }  \n    out(root);  \n    return 0;  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-11 \u662f\u5426\u5b8c\u5168\u4e8c\u53c9\u641c\u7d22\u6811<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-c0869a3f9ffc8f6842e30f73c4c88aa6\"><code>#include&lt;stdio.h>\n#include&lt;stdlib.h>\ntypedef struct TNode* BinTree;\nstruct TNode{\n    int Data;\n    BinTree Left;\n    BinTree Right;\n};\nBinTree Insert( BinTree BST, int x )\n{\n    if(!BST){\n        BST=(BinTree)malloc(sizeof(struct TNode));\n        BST->Data=x;\n        BST->Left=BST->Right=NULL;\n    }\n    else{\n        if(x>BST->Data) BST->Left=Insert( BST->Left, x );\n        else if(x&lt;BST->Data) BST->Right=Insert( BST->Right, x );\n    }\n    return BST;\n}\nvoid Out(BinTree BST)\n{\n    int i,front=0,tail=0,p=0;\n    BinTree a&#91;30],x;\n    a&#91;++tail]=BST;\n    while(tail!=front){\n        x=a&#91;++front];\n        if(p==0) {\n            printf(\"%d\",x->Data);\n            p=1;\n        }\n        else printf(\" %d\",x->Data);\n        if(x->Left) a&#91;++tail]=x->Left;\n        if(x->Right) a&#91;++tail]=x->Right;\n    }\n}\nvoid Pan(BinTree BST)\n{\n    int i,front=0,tail=0,q=0;\n    BinTree a&#91;30],x;\n    a&#91;++tail]=BST;\n    while(tail!=front){\n        x=a&#91;++front];\n        if(!x->Left&amp;&amp;x->Right){\n        \tprintf(\"\\nNO\");\n        \treturn;\n\t\t}\n        if(x->Left&amp;&amp;x->Right){\n\t\t\ta&#91;++tail]=x->Left;\n\t\t\ta&#91;++tail]=x->Right;\n\t\t}\n        if(!x->Right&amp;&amp;x->Left){\n\t\t\ta&#91;++tail]=x->Left;\n\t\t\tq=1;\n\t\t}\n\t\tif(!x->Right&amp;&amp;!x->Left) q=1;\n\t\twhile(q==1&amp;&amp;tail!=front){\n\t\t\tx=a&#91;++front];\n\t\t\tif(x->Left||x->Right){\n\t\t\t\tprintf(\"\\nNO\");\n        \t\treturn;\n\t\t\t}\n\t\t}\n    }\n    printf(\"\\nYES\");\n}\nint main()\n{\n    int n,i,x;\n    BinTree BST=NULL;\n    scanf(\"%d\",&amp;n);\n    for(i=0;i&lt;n;i++){\n        scanf(\"%d\",&amp;x);\n        BST=Insert(BST, x);\n    }\n    Out(BST);\n    Pan(BST);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-12 \u6784\u9020\u54c8\u592b\u66fc\u6811-\u65e0\u5e8f\u8f93\u5165<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-531c1094d9f78d1d4c0d17cbc2bde971\"><code>#include &lt;iostream>\n#include &lt;climits>\nusing namespace std;\n\nstruct node{\n    int data, parent, lson, rson;\n}sxr&#91;22];\n\nint n;\n\nvoid inorder_traversal(int index) {\n    if (index==-1){\n        return;\n    }\n    inorder_traversal(sxr&#91;index].lson);\n    printf(\"%d \", sxr&#91;index].data);\n    inorder_traversal(sxr&#91;index].rson);\n}\n\nvoid select(node hf&#91;], int k, int &amp;t1, int &amp;t2){\n    int min1 = INT_MAX, min2 = INT_MAX;\n    t1 = t2 = -1;\n    for(int i = 0; i &lt; n + k; i++){ \n        if(hf&#91;i].parent == -1 &amp;&amp; hf&#91;i].data &lt; min1){\n            min2 = min1;\n            t2 = t1;\n            min1 = hf&#91;i].data;\n            t1 = i;\n        }\n        else if(hf&#91;i].parent == -1 &amp;&amp; hf&#91;i].data &lt; min2 &amp;&amp; t1 != i){\n            min2 = hf&#91;i].data;\n            t2 = i;\n        }\n    }\n}\n\n\nint main(){\n    int i, j,k;\n    cin >> n;\n    for(i = 0; i &lt; n; i++){\n        cin >> sxr&#91;i].data;\n        sxr&#91;i].parent = sxr&#91;i].lson = sxr&#91;i].rson = -1;\n    }\n    for(k = 0; k &lt; n-1; k++){\n        select(sxr, k, i, j);\n        if(i == -1 || j == -1) break;\n        sxr&#91;n + k].data = sxr&#91;i].data + sxr&#91;j].data;\n        sxr&#91;n + k].parent = -1;\n        sxr&#91;n + k].lson = i;\n        sxr&#91;n + k].rson = j;\n        sxr&#91;i].parent = sxr&#91;j].parent = n + k;\n    }\n\n    for(i=0;i&lt;2*n-1;i++){\n        if(sxr&#91;i].parent==-1){\n            inorder_traversal(i);\n            break;\n        }\n    }\n\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-13 \u56fe\u7684\u5b58\u50a8-\u90bb\u63a5\u8868<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-e34cb7d05a75312a1868fd000eab78b5\"><code>#include &lt;bits\/stdc++.h>\nusing namespace std;\nint main(){\n    int n,m,s,x,y;\n    cin>>n>>m>>s;\n    vector&lt;int> v&#91;n];\n    for(int i=0;i&lt;m;i++){\n        cin>>x>>y;\n        v&#91;x-1].push_back(y-1);\n        if(s==0){\n            v&#91;y-1].push_back(x-1);\n        }\n    }\n    for(int i=0;i&lt;n;i++){\n        cout&lt;&lt;i&lt;&lt;\":\";\n        for(int j=v&#91;i].size()-1;j>=0;j--){\n            cout&lt;&lt;v&#91;i]&#91;j]&lt;&lt;\" \";\n        }\n        cout&lt;&lt;endl;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-14 \u56fe\u7684\u5b58\u50a8-\u90bb\u63a5\u77e9\u9635<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-1effd943a6f9271104edf4dd0ae540f9\"><code>#include &lt;bits\/stdc++.h>\nusing namespace std;\nint main(){\n    int n,m,s,sxr&#91;52]&#91;52]={0},x,y;\n    cin>>n>>m>>s;\n    for(int i=0;i&lt;m;i++){\n        cin>>x>>y;\n        sxr&#91;x]&#91;y]=1;\n    }\n    if(s==0){\n        for(int i=1;i&lt;=n;i++){\n            for(int j=1;j&lt;=n;j++){\n                if(sxr&#91;i]&#91;j]!=0){\n                    sxr&#91;j]&#91;i]=sxr&#91;i]&#91;j];\n                }\n                if(sxr&#91;j]&#91;i]!=0){\n                    sxr&#91;i]&#91;j]=sxr&#91;j]&#91;i];\n                }\n            }\n        }\n    }\n\n\n    for(int i=1;i&lt;=n;i++){\n        for(int j=1;j&lt;=n;j++){\n            cout&lt;&lt;sxr&#91;i]&#91;j]&lt;&lt;\" \";\n        }\n        cout&lt;&lt;endl;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-15 \u56fe\u7684\u5148\u5e7f\u641c\u7d22<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-a04f0cbfa027bb21429e9ac3938371e0\"><code>#include&lt;stdio.h>\n#include&lt;malloc.h>\ntypedef struct edgenode{\n    int adjacent;\n    struct edgenode *next;\n}edgenode,*eptr;\ntypedef struct{\n    int mark;\n    eptr firstedge;\n}hnode;\n\nvoid creatlist(hnode l&#91;],int n,int m){\n    eptr p;\n    int v1,v2;\n    for (int i=0;i&lt;n;i++){\n        l&#91;i].mark=0;\n        l&#91;i].firstedge=NULL;\n    }\n    for (int i=0;i&lt;m;i++){\n        scanf(\"%d %d\",&amp;v1,&amp;v2);\n        p=(eptr)malloc(sizeof(edgenode));\n        p->adjacent=v2-1;\n        p->next=l&#91;v1-1].firstedge;\n        l&#91;v1-1].firstedge=p;\n        p=(eptr)malloc(sizeof(edgenode));\n        p->adjacent=v1-1;\n        p->next=l&#91;v2-1].firstedge;\n        l&#91;v2-1].firstedge=p;\n    }\n}\nvoid bfs(hnode l&#91;],int n,int v){\n    eptr p;\n    int u,w,first,last,q&#91;n];\n    first=last=0;\n    for(u=0;u&lt;n;u++)l&#91;u].mark=0;\n    for (u=0;u&lt;n;u++)\n        if (l&#91;v].mark==0){\n            q&#91;last++]=v;\n            l&#91;v].mark=1;\n            while(first!=last){\n                v=q&#91;first++];\n                printf(\"%d \",v+1);\n                p=l&#91;v].firstedge;\n                while(p!=NULL){\n                    w=p->adjacent;\n                    if (l&#91;w].mark==0){\n                        q&#91;last++]=w;\n                        l&#91;w].mark=1;\n                    }\n                    p=p->next;\n                }\n            }\n        }\n}\nint main(){\n    int n,m,s;\n    int num=0;\n    scanf(\"%d %d %d\",&amp;n,&amp;m,&amp;s);\n    hnode l&#91;10];\n    creatlist(l,n,m);\n    bfs(l,n,s-1);\n    for (int i=0;i&lt;n;i++){\n        if (l&#91;i].mark==1){\n            num++;\n        }\n    }\n    if (num!=n){\n        printf(\"\\n0\");\n    }\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p><strong>7-16 \u6700\u5c0f\u751f\u6210\u6811-kruskal\u7b97\u6cd5<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-b4b0452e3c935f8b8d9f02d70f812bd6\"><code>#include &lt;iostream>\n#include &lt;vector>\n#include &lt;algorithm>\n#include &lt;set>\n\nusing namespace std;\n\nstruct Edge {\n    int u, v, cost;\n    bool operator&lt;(const Edge&amp; other) const {\n        return cost &lt; other.cost;\n    }\n};\n\nint find(int x, vector&lt;int>&amp; parent) {\n    if (parent&#91;x] != x) {\n        parent&#91;x] = find(parent&#91;x], parent);\n    }\n    return parent&#91;x];\n}\n\nbool unionSet(int x, int y, vector&lt;int>&amp; parent, vector&lt;int>&amp; rank) {\n    int rootX = find(x, parent);\n    int rootY = find(y, parent);\n    if (rootX != rootY) {\n        if (rank&#91;rootX] &lt; rank&#91;rootY]) {\n            parent&#91;rootX] = rootY;\n        } else if (rank&#91;rootX] > rank&#91;rootY]) {\n            parent&#91;rootY] = rootX;\n        } else {\n            parent&#91;rootY] = rootX;\n            rank&#91;rootX]++;\n        }\n        return true;\n    }\n    return false;\n}\n\nint main() {\n    int N, M;\n    cin >> N >> M;\n    \n    vector&lt;Edge> edges;\n    for (int i = 0; i &lt; M; ++i) {\n        int u, v, cost;\n        cin >> u >> v >> cost;\n        edges.push_back({u, v, cost});\n    }\n    \n    sort(edges.begin(), edges.end());\n    \n    vector&lt;int> parent(N + 1);\n    vector&lt;int> rank(N + 1, 0);\n    for (int i = 1; i &lt;= N; ++i) {\n        parent&#91;i] = i;\n    }\n    \n    vector&lt;Edge> mst;\n    for (const Edge&amp; edge : edges) {\n        if (unionSet(edge.u, edge.v, parent, rank)) {\n            mst.push_back(edge);\n        }\n    }\n    \n    for (const Edge&amp; edge : mst) {\n        cout &lt;&lt; min(edge.u, edge.v) &lt;&lt; \",\" &lt;&lt; max(edge.u, edge.v) &lt;&lt; \",\" &lt;&lt; edge.cost &lt;&lt; endl;\n    }\n    \n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-17 \u6700\u5c0f\u751f\u6210\u6811-Prim\u7b97\u6cd5\uff08\u4ece\u4efb\u610f\u9876\u70b9\u5f00\u59cb\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-803f987b5e167a742a07409bf750fd3c\"><code>#include&lt;bits\/stdc++.h>\nusing namespace std;\nint inf=0x3f3f3f3f;\nint graph&#91;10000]&#91;10000]={0};\nint lowcost&#91;10000]={0};\/\/\u70b9\u96c6\nint tree&#91;10000]={0};\nint m,n,ls;\nvoid prim(int s)\n{\n    for(int i=1;i&lt;=n;i++)\n    {\n        if(i==s)\n            lowcost&#91;i]=0;\n        else\n        lowcost&#91;i]=graph&#91;s]&#91;i];\n        tree&#91;i]=s;\/\/\u521d\u59cb\u5316\uff0c\u6240\u6709\u7684\u8fb9\u90fd\u5f85\u9009\n    }\n    int minn,pos;\n    for(int i=1;i&lt;n;i++)\/\/\u5faa\u73af\u4e86n-1\u6b21\uff0c\u56e0\u4e3an\u4e2a\u70b9\uff0cn-1\u4e2a\u8fb9\n    {\n        minn=inf;\n        for(int j=1;j&lt;=n;j++)\n        {\n            if(lowcost&#91;j]!=0&amp;&amp;lowcost&#91;j]&lt;minn)\n            {\n                minn=lowcost&#91;j];\n                pos=j;\n            }\/\/\u8fd9\u4e2a\u627e\u7684\u5c31\u662f\u70b9\u96c6\u5468\u56f4\u7684\u6700\u5c0f\u8fb9\n        }\n        cout&lt;&lt;(tree&#91;pos]&lt;pos?tree&#91;pos]:pos)&lt;&lt;\",\"&lt;&lt;(tree&#91;pos]>pos?tree&#91;pos]:pos)&lt;&lt;\",\"&lt;&lt;graph&#91;tree&#91;pos]]&#91;pos]&lt;&lt;endl;\/\/\u6bcf\u627e\u5230\u4e00\u4e2a\u8fb9\u5c31\u8f93\u51fa\u4e00\u4e2a\u8fb9\n        if(minn==inf)\n            break;\n        lowcost&#91;pos]=0;\/\/\u52a0\u5165\uff01\uff01\n        for(int j=1;j&lt;=n;j++)\n        {\n            if(lowcost&#91;j]!=0&amp;&amp;graph&#91;pos]&#91;j]&lt;lowcost&#91;j])\/\/\u56e0\u4e3a\u6ca1\u5728\u70b9\u96c6\u91cc\uff0cs\u5230j\u6bd4\u8f83\u5927\uff0cpos\u5230j\u5c0f\uff0c\u5c31\u66f4\u65b0\u4e00\u4e0b\n            {\n                lowcost&#91;j]=graph&#91;pos]&#91;j];\/\/\u5176\u5b9e\u5c31\u662f\u70b9\u96c6\u5230j\u6700\u77ed\u7684\u8ddd\u79bb\n                tree&#91;j]=pos;\/\/\u52a0\u5165\u5230tree\u7684\u5f85\u9009\uff0c\u4e0b\u6b21\u5faa\u73af\u4f1a\u9009\u51fa\u6765\u5408\u9002\u7684\uff0c\u5230\u65f6\u5019\u8fd9\u91cc\u7684j\u4f1a\u662f\u5408\u9002\u7684pos\uff0c\u8fd9\u91cc\u7684pos\u5bf9\u5e94\u4e0a\u4e00\u6b21\u5408\u9002\u7684\u503c\u3002\n            }\n        }\n    }\n}\nint main()\n{\n    cin>>n>>m>>ls;\n    for(int i=1;i&lt;=n;i++)\n        for(int j=1;j&lt;=n;j++)\n            graph&#91;i]&#91;j]=inf;\n    for(int i=0;i&lt;m;i++)\n    {\n        int a,b;\n        cin>>a>>b;\n        cin>>graph&#91;a]&#91;b];\n        graph&#91;b]&#91;a]=graph&#91;a]&#91;b];\n    }\n    prim(ls);\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-18 \u6700\u77ed\u8def\u5f84-Dijkstra<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-4ae8b4b2e274a667a061c0616de979d7\"><code>#include &lt;stdio.h>\n#include &lt;stdlib.h>\n#include &lt;stdbool.h>\n#include &lt;limits.h>\n\n#define MAX_SIZE 10\n#define INF 1000\n\nvoid dijkstra(int graph&#91;MAX_SIZE]&#91;MAX_SIZE], int start, int N) {\n    int distance&#91;MAX_SIZE];  \/\/ \u5b58\u50a8\u8d77\u59cb\u70b9\u5230\u5404\u4e2a\u70b9\u7684\u6700\u77ed\u8ddd\u79bb\n    bool visited&#91;MAX_SIZE];  \/\/ \u8bb0\u5f55\u8282\u70b9\u662f\u5426\u5df2\u8bbf\u95ee\n    int i,j;\n\n    \/\/ \u521d\u59cb\u5316\u8ddd\u79bb\u548c\u8bbf\u95ee\u72b6\u6001\n    for (i = 0; i &lt; N; i++) {\n        distance&#91;i] = INF;\n        visited&#91;i] = false;\n    }\n\n    \/\/ \u8bbe\u7f6e\u8d77\u59cb\u70b9\u7684\u6700\u77ed\u8ddd\u79bb\u4e3a0\n    distance&#91;start] = 0;\n\n    \/\/ \u4f9d\u6b21\u627e\u5230\u8ddd\u79bb\u6700\u77ed\u7684\u8282\u70b9\u5e76\u66f4\u65b0\u5176\u4ed6\u8282\u70b9\u7684\u6700\u77ed\u8ddd\u79bb\n    for (i = 0; i &lt; N; i++) {\n        int min_dis = INF;\n        int min_node = -1;\n\n        \/\/ \u627e\u5230\u5f53\u524d\u6700\u5c0f\u8ddd\u79bb\u7684\u8282\u70b9\n        for (j = 0; j &lt; N; j++) {\n            if (!visited&#91;j] &amp;&amp; distance&#91;j] &lt; min_dis) {\n                min_dis = distance&#91;j];\n                min_node = j;\n            }\n        }\n\n        \/\/ \u6807\u8bb0\u8be5\u8282\u70b9\u5df2\u8bbf\u95ee\n        visited&#91;min_node] = true;\n\n        \/\/ \u66f4\u65b0\u5176\u4ed6\u8282\u70b9\u7684\u6700\u77ed\u8ddd\u79bb\n        for (j = 0; j &lt; N; j++) {\n            if (!visited&#91;j] &amp;&amp; graph&#91;min_node]&#91;j] != INF &amp;&amp; distance&#91;j] > distance&#91;min_node] + graph&#91;min_node]&#91;j]) {\n                distance&#91;j] = distance&#91;min_node] + graph&#91;min_node]&#91;j];\n            }\n        }\n    }\n\n    \/\/ \u8f93\u51fa\u6700\u77ed\u8ddd\u79bb\n    for (i = 0; i &lt; N; i++) {\n        if (distance&#91;i] >=1000) {\n            printf(\"%d->%d:no path\\n\", start + 1, i + 1);\n        } else {\n            printf(\"%d->%d:%d\\n\", start + 1, i + 1, distance&#91;i]);\n        }\n    }\n}\n\nint main() {\n    int N, M, directed;\n    int i,j,u, v, time, start;\n\n    \/\/ \u8bfb\u53d6\u8f93\u5165\n    scanf(\"%d %d %d\", &amp;N, &amp;M, &amp;directed);\n\n    \/\/ \u6784\u5efa\u56fe\u7684\u90bb\u63a5\u77e9\u9635\n    int graph&#91;MAX_SIZE]&#91;MAX_SIZE];\n    for (i = 0; i &lt; N; i++) {\n        for (j = 0; j &lt; N; j++) {\n            graph&#91;i]&#91;j] = INF;\n        }\n    }\n\n    for (i = 0; i &lt; M; i++) {\n        scanf(\"%d %d %d\", &amp;u, &amp;v, &amp;time);\n        graph&#91;u-1]&#91;v-1] = time;\n        if (!directed) {\n            graph&#91;v-1]&#91;u-1] = time;\n        }\n    }\n\n    \/\/ \u9009\u62e9\u8d77\u59cb\u70b9\n    scanf(\"%d\", &amp;start);\n    start--;\n\n    \/\/ \u8c03\u7528Dijkstra\u7b97\u6cd5\u8ba1\u7b97\u6700\u77ed\u8ddd\u79bb\n    dijkstra(graph, start, N);\n\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-19 \u6c42\u6700\u77ed\u8def\u5f84-flyod\u7b97\u6cd5<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-7a03f8aba3c4974cd932044ecd358d86\"><code>#include &lt;bits\/stdc++.h>\nusing namespace std;\n\nint graph&#91;15]&#91;15];\nint n,m,s,x,y;\n\nvoid flyod(){\n    for(int k=0;k&lt;n;k++){\n        for(int i=0;i&lt;n;i++){\n            for(int j=0;j&lt;n;j++){\n                if(graph&#91;i]&#91;k]+graph&#91;k]&#91;j]&lt;graph&#91;i]&#91;j]){\n                    graph&#91;i]&#91;j]=graph&#91;i]&#91;k]+graph&#91;k]&#91;j];\n                }\n            }\n        }\n    }\n    return;\n}\n\n\nint main(){\n    int maxx,maxxnum;\n    memset(graph,999,sizeof(graph));\n    cin>>n>>m>>s;\n    for(int i=0;i&lt;n;i++){\n        graph&#91;i]&#91;i]=0;\n    }\n    for(int i=0;i&lt;m;i++){\n        cin>>x>>y;\n        cin>>graph&#91;x-1]&#91;y-1];\n        if(s==0){\n            graph&#91;y-1]&#91;x-1]=graph&#91;x-1]&#91;y-1];\n        }\n    }\n    flyod();\n    \/*\n    for(int i=0;i&lt;n;i++){\n        for(int j=0;j&lt;n;j++){\n            cout&lt;&lt;graph&#91;i]&#91;j]&lt;&lt;\" \";\n        }\n        cout&lt;&lt;endl;\n    }\n    *\/\n    maxx=INT_MAX;\n    maxxnum=0;\n    for(int i=0;i&lt;n;i++){\n        int smax=0;\n        for(int j=0;j&lt;n;j++){\n            if(graph&#91;i]&#91;j]>smax){\n                smax=graph&#91;i]&#91;j];\n            }\n        }\n        if(smax&lt;maxx){\n            maxx=smax;\n            maxxnum=i;\n        }\n    }\n    cout&lt;&lt;maxxnum+1;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-20 \u6709\u5411\u56fe\u7684\u62d3\u6251\u5e8f\u5217<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-2e212f3f4c62e560188e7a7bbc81b5ba\"><code>#include &lt;bits\/stdc++.h>\n \nusing namespace std;\n \n#define MAX_LENGTH 1010\n \nvector&lt;int> G&#91;MAX_LENGTH];\nint n, m, inDegree&#91;MAX_LENGTH];\nstack&lt;int> s;\n \nbool TopologicalOrder() {\n    int num = 0;\n    for (int i = 1; i &lt;= n; i++) {\n        if (inDegree&#91;i] == 0) {\n            s.push(i);\n        }\n    }\n    while (s.size()) {\n        int u = s.top();\n        cout &lt;&lt; u &lt;&lt; \" \";\n        s.pop();\n        for (int i = 0; i &lt; G&#91;u].size(); i++) {\n            int v = G&#91;u]&#91;i];\n            inDegree&#91;v]--;\n            if (inDegree&#91;v] == 0) {\n                s.push(v);\n            }\n        }\n        num++;\n    }\n    if (num == n) return true;\n    else return false;\n}\n \nint main() {\n    int x, y;\n    cin >> n >> m;\n    memset(inDegree, 0, sizeof(inDegree));\n    for (int i = 1; i &lt;= m; i++) {\n        cin >> x >> y;\n        inDegree&#91;y]++;\n        if(!G&#91;x].size()) G&#91;x].push_back(y);\n        else{\n            G&#91;x].insert(G&#91;x].begin(), y);\n        }\n    }\n\n    if (!TopologicalOrder()) {\n        cout &lt;&lt; endl;\n        cout &lt;&lt; \"0\" &lt;&lt; endl;\n    }\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-21 \u5192\u6ce1\u6392\u5e8f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-42faa46915aacf922a848e62c64a062d\"><code>#include &lt;iostream>\nusing namespace std;\nint main(void)\n{\n    int i,j,n,a&#91;100],tem;\n    cin >> n;\n    for(i=0;i&lt;n;i++) cin >> a&#91;i];\n    for(i=0;i&lt;3;i++)\n    {\n        for(j=n-1;j>i;j--)\n        {\n            if(a&#91;j]&lt;a&#91;j-1])\n            {\n                tem=a&#91;j];\n                a&#91;j]=a&#91;j-1];\n                a&#91;j-1]=tem;\n            }\n        }\n        for(j=0;j&lt;n;j++) cout &lt;&lt; a&#91;j] &lt;&lt; \" \";\n        cout &lt;&lt; endl;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-22 \u7b80\u5355\u9009\u62e9\u6392\u5e8f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-4852e880c88df4a367e5580621e49853\"><code>#include &lt;iostream>;\nusing namespace std;\nint main(void)\n{\n    int n,i,j,tem,a&#91;100],max,maxj;\n    cin >> n;\n    for(i=0;i&lt;n;i++) cin >> a&#91;i];\n\n    \n    for(i=0;i&lt;3;i++)\n    {\n        max=a&#91;0],maxj=0;\n        for(j=0;j&lt;n-i;j++)\n        {\n            if(a&#91;j]>max)\n            {\n                max=a&#91;j];\n                maxj=j;\n            }\n        }\n        tem=a&#91;n-i-1];\n        a&#91;n-i-1]=a&#91;maxj];\n        a&#91;maxj]=tem;\n        for(j=0;j&lt;n;j++) cout &lt;&lt; a&#91;j] &lt;&lt;\" \";\n        cout &lt;&lt; endl;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-23 \u76f4\u63a5\u63d2\u5165\u6392\u5e8f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-7a051a3458bd95680be24d0e0d1e612b\"><code>#include &lt;iostream>\nusing namespace std;\nint main(void)\n{\n    int n,i,j,a&#91;100],count,tem;\n    cin >> n;\n    for(i=0;i&lt;n;i++) cin >> a&#91;i];\n    for(i=0;i&lt;3;i++)\n    {\n        for(j=0;j&lt;i+1;j++)\n        {\n            if(a&#91;i+1]&lt;=a&#91;j])\n            {\n                tem=a&#91;i+1];\n                a&#91;i+1]=a&#91;j];\n                a&#91;j]=tem;\n            }\n        \n        }\n        for(j=0;j&lt;n;j++) cout &lt;&lt; a&#91;j] &lt;&lt;\" \";\n        cout &lt;&lt; endl;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-24 \u9012\u5f52\u4e8c\u8def\u5f52\u5e76\u6392\u5e8f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-a7054375f83104ca5d7ecbd0b96ae014\"><code>#include &lt;iostream>\nusing namespace std;\n\nint n,a&#91;120],sxr=0;\n\nvoid merage(int p,int q,int s,int t){\n    int i=p,j=s,k=p-1,b&#91;n];\n    while((i&lt;=q)&amp;&amp;(j&lt;=t))\n        if(a&#91;i]&lt;=a&#91;j])\n            b&#91;++k]=a&#91;i++];\n        else\n            b&#91;++k]=a&#91;j++];\n    while(i&lt;=q)\n        b&#91;++k]=a&#91;i++];\n    while(j&lt;=t)\n        b&#91;++k]=a&#91;j++];\n    for(i=p;i&lt;=t;i++)\n        a&#91;i]=b&#91;i];\n}\nvoid merage_sort(int i,int j){\n    int k;\n    if(i&lt;j){\n        k=(i+j)\/2;\n        merage_sort(i,k);\n        merage_sort(k+1,j);\n        merage(i,k,k+1,j);\n        if(sxr&lt;3){\n            for(int l=0;l&lt;n;l++){\n                cout&lt;&lt;a&#91;l]&lt;&lt;\" \";\n            }\n            sxr++;\n            cout&lt;&lt;endl;\n        }\n    }\n}\n\nint main(){\n    cin>>n;\n    for(int i=0;i&lt;n;i++){\n        cin>>a&#91;i];\n    }\n    merage_sort(0,n-1);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-25 PAT\u6392\u540d\u6c47\u603b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-d6fa6a010a69a420e592084863460b9a\"><code>#include&lt;iostream>\n#include&lt;algorithm>\n#include&lt;vector>\nusing namespace std;\nstruct node\n{\n\tstring num;\/\/\u4e0d\u80fd\u7528Longlong\uff0clonglong\u7b2c\u4e00\u4f4d\u4e3a0\u4f1a\u81ea\u52a8\u5220\u9664 \n\tint score;\n\tint sumrank;\n\tint rank;\n\tint work;\n}student&#91;30005];\/\/\u5b58\u5b66\u751f\u4fe1\u606f \nbool cmp(node* a,node* b)\n{\n\tif(a->score!=b->score)\n\treturn a->score>b->score;\n\treturn a->num&lt;b->num;\n}\/\/\u6bd4\u8f83\u51fd\u6570\uff0c\u5206\u6570\u4e0d\u7b49\u6309\u5b66\u53f7\u6392 \nint main()\n{\n\tint T,t,n,i,j,k,s=0;\n\tvector&lt;node*> q;\/\/vector\u5b58\u6307\u5411\u7ed3\u6784\u4f53\u7684\u6307\u9488 \n\tvector&lt;node*>::iterator it;\n\tcin>>T;\n\tfor(i=1;i&lt;=T;i++)\n\t{\n\t\tq.clear();\/\/\u6e05\u7a7a\uff0c\u5426\u5219\u4f1a\u5728\u539f\u57fa\u7840\u4e0a\u5b58\u6570\u636e \n\t\tcin>>n;\n\t\twhile(n--)\n\t\t{\n\t\t\tcin>>student&#91;s].num>>student&#91;s].score;\n\t\t\tstudent&#91;s].work=i;\n\t\t\tq.push_back(&amp;student&#91;s]);\/\/\u538b\u5165\u7ed3\u6784\u4f53\u7684\u6307\u9488 \n\t\t\ts++;\/\/\u5b66\u751f\u6570\u91cf\u52a01 \n\t\t}\n\t\tsort(q.begin(),q.end(),cmp);\n\t\t(*q.begin())->rank=1;\/\/\u6ce8\u610f\u8fd9\u5730\u65b9\u7684\u8fd0\u7528\uff0c(*q.begin())\u662f\u6307\u5411\u7ed3\u6784\u4f53\u7684\u6307\u9488\uff0c\u5fc5\u987b\u52a0\u62ec\u53f7\uff0c->\u7684\u4f18\u5148\u7ea7\u5927\u4e8e*\uff0c*a.b\u7b49\u7ea7\u4e8ea->b \n\t\tfor(it=q.begin()+1,j=2;it!=q.end();it++,j++)\n\t\t{\n\t\t\t(*it)->rank=j;\/\/(*it)\u662f\u7ed3\u6784\u4f53\u7684\u5730\u5740 \n\t\t\tif((*it)->score==(*(it-1))->score)(*it)->rank=(*(it-1))->rank;\n\t\t}\t\n\t}\n   q.clear();\n   for(i=0;i&lt;s;i++)\n   q.push_back(&amp;student&#91;i]);\n\t\n\t\n\t\tsort(q.begin(),q.end(),cmp);\n\t(*q.begin())->sumrank=1;\n\tfor(it=q.begin()+1,j=2;it!=q.end();it++,j++)\n\t{\n\t\t(*it)->sumrank=j;\n\t\tif((*it)->score==(*(it-1))->score) (*it)->sumrank=(*(it-1))->sumrank;\n\t}\n\t\n\tcout&lt;&lt;s&lt;&lt;endl;\n\tfor(i=0;i&lt;s;i++)\n\tcout&lt;&lt;q&#91;i]->num&lt;&lt;\" \"&lt;&lt;q&#91;i]->sumrank&lt;&lt;\" \"&lt;&lt;q&#91;i]->work&lt;&lt;\" \"&lt;&lt;q&#91;i]->rank&lt;&lt;endl;\n\t\n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-26 \u5965\u8fd0\u6392\u884c\u699c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-c3e4b61c7e7ed88a18eab74daf293a23\"><code>#include&lt;stdio.h>\n#include&lt;malloc.h>\n#include&lt;stdlib.h>\n#include&lt;string.h>\nstruct jp{\n    double jin;\n    double jiang;\n    double people;\n    double aver_jin;\n    double aver_jiang;\n}a&#91;300];\nint main()\n{\n    int N,M,i,j;\n    int b&#91;500];\/\/\u5b58\u50a8\u6700\u540e\u4e00\u884cM\u4e2a\u524d\u6765\u54a8\u8be2\u7684\u56fd\u5bb6\u7684\u7f16\u53f7\n    int p0,p1,p2,p3;\n    scanf(\"%d%d\",&amp;N,&amp;M);\n    for(i=0;i&lt;N;i++)\n    {\n        scanf(\"%lf%lf%lf\",&amp;a&#91;i].jin,&amp;a&#91;i].jiang,&amp;a&#91;i].people);\n        a&#91;i].aver_jin=a&#91;i].jin\/a&#91;i].people;\n        a&#91;i].aver_jiang=a&#91;i].jiang\/a&#91;i].people;\n    }\n    for(i=0;i&lt;M;i++)\n        scanf(\"%d\",&amp;b&#91;i]);\n    for(i=0;i&lt;M;i++)\n    {\n        p0=0;p1=0;p2=0;p3=0;\n        for(j=0;j&lt;N;j++)\n        {\n            if(a&#91;b&#91;i]].jin>=a&#91;j].jin)  p0++;\n            if(a&#91;b&#91;i]].jiang>=a&#91;j].jiang)  p1++;\n            if(a&#91;b&#91;i]].aver_jin>=a&#91;j].aver_jin) p2++;\n            if(a&#91;b&#91;i]].aver_jiang>=a&#91;j].aver_jiang) p3++;\n        }\n        int max=p0,t=1;\n        \/\/\u8ba1\u7b97\u91cd\u8981\u5ea6\u6392\u540d\u4e3a\u91d1\u724c\uff0c\u5956\u724c\uff0c\u4eba\u5747\u91d1\u724c\uff0c\u4eba\u5747\u5956\u724c\n        if(max&lt;p1){max=p1;t=2;}\n        if(max&lt;p2){max=p2;t=3;}\n        if(max&lt;p3){max=p3;t=4;}\n        if(i==0)\n            printf(\"%d:%d\",N-max+1,t);\n        else printf(\" %d:%d\",N-max+1,t);\n        \/\/N-max+1\u4e3a\u8be5\u56fd\u5bb6\u6240\u80fd\u62ff\u5230\u7684\u6700\u9ad8\u540d\u6b21\u7684\u6392\u5e8f\u65b9\u5f0f\n        \/\/t\u4e3a\u6b64\u65b9\u5f0f\u80fd\u591f\u83b7\u5f97\u7684\u6700\u9ad8\u7684\u6392\u540d\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-27 \u5bfb\u627e\u5927\u5bcc\u7fc1<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-c28fe97caa36c277b26dc1b8f6f71452\"><code>#include &lt;bits\/stdc++.h>\nusing namespace std;\nbool cmp(int x,int y){\n    if(x>=y)\n        return 1;\n    return 0;\n}\n\nint main(){\n    int sxr&#91;1000050],n,m;\n    cin>>n>>m;\n    for(int i=0;i&lt;n;i++){\n        cin>>sxr&#91;i];\n    }\n    sort(sxr,sxr+n,cmp);\n    if(n>=m){\n        cout&lt;&lt;sxr&#91;0];\n        for(int i=1;i&lt;m;i++){\n            cout&lt;&lt;\" \"&lt;&lt;sxr&#91;i];\n        }\n    }\n    else{\n        cout&lt;&lt;sxr&#91;0];\n        for(int i=1;i&lt;n;i++){\n            cout&lt;&lt;\" \"&lt;&lt;sxr&#91;i];\n        }\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-larger-font-size\"><strong>7-28 \u58eb\u5175\u6392\u961f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-accent-2-color has-text-color has-link-color wp-elements-0074727a93a61cd364db169b447ee135\"><code>#include&lt;cstdio>\n#include&lt;algorithm>\/\/sort\u51fd\u6570 \n#include&lt;cstdlib> \/\/abs\u51fd\u6570\n\nusing namespace std;\n\nint main()\n{\n\tint n;\/\/\u58eb\u5175\u6570\n\tscanf(\"%d\",&amp;n);\n\t\n\tint x&#91;10000],y&#91;10000];\n\t\/\/x\u6570\u7ec4\u5b58\u50a8\u58eb\u5175\u7684\u6a2a\u5750\u6807\uff0cy\u6570\u7ec4\u5b58\u50a8\u58eb\u5175\u7684\u7eb5\u5750\u6807\n\tint sum=0,rex,rey;\n\t\/\/sum\u8bb0\u5f55\u6b65\u6570\u4e4b\u548c\uff0crex\u8bb0\u5f55x\u65b9\u5411\u7684\u4e2d\u4f4d\u6570\uff0crey\u8bb0\u5f55y\u65b9\u5411\u7684\u4e2d\u4f4d\u6570\n\t\n\tint i;\n\tfor(i=1;i&lt;=n;i++)\n\t\tscanf(\"%d%d\",x+i,y+i);\t\n\t\/\/\u6570\u636e\u7684\u8f93\u5165\u5230x&#91;1]~x&#91;n],y&#91;1]~y&#91;n],\u6b64\u5904\u4f7f\u7528\u7684\u662f\u6570\u7ec4\u5730\u5740\u6cd5 \n\t\n\tsort(x+1,x+n+1);\n\tsort(y+1,y+n+1);\n\t\/\/\u5bf9\u6570\u636ex&#91;1]~x&#91;n],y&#91;1]~y&#91;n]\u5206\u522b\u8fdb\u884c\u7531\u5c0f\u5230\u5927\u7684\u6392\u5e8f\n\t\n\tfor(i=1;i&lt;=n;i++)\n\t\tx&#91;i]=x&#91;i]-i;\n\t\/\/\u6784\u9020x1-1\uff0cx2-2\uff0c......\uff0cxn-n\u6570\u5217 \n\t\n\tsort(x+1,x+n+1);\n\t\/\/\u5bf9\u65b0\u6570\u5217\u8fdb\u884c\u6392\u5e8f\n\t\n\tif(n%2==0)\/\/n\u4e3a\u5076\u6570 \n\t{\n\t\trex = (x&#91;n\/2]+x&#91;n\/2+1])\/2;\n\t\trey = (y&#91;n\/2]+y&#91;n\/2+1])\/2;\n\t}\n\telse\/\/n\u4e3a\u5947\u6570 \n\t{\n\t\trex = x&#91;n\/2+1];\n\t\trey = y&#91;n\/2+1];\t\n\t} \n\t\n\t\/\/\u4e0b\u9762\u8ba1\u7b97\u6700\u5c0f\u79fb\u52a8\u6b65\u6570\n\tfor(i=1;i&lt;=n;i++)\n\t\tsum += abs(x&#91;i]-rex)+abs(y&#91;i]-rey);\n\t\t\n\tprintf(\"%d\",sum);\n\t\/\/\u8f93\u51fa\u7ed3\u679c\n\treturn 0;\n } \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8\u610f\uff1a\u672c\u9875\u9762\u4e2d\u5927\u90e8\u5206\u4ee3\u7801\u90fd\u662f\u7528C++\u7f16\u5199\uff0c\u5728\u63d0\u4ea4\u65f6 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5,22],"tags":[9,10],"_links":{"self":[{"href":"https:\/\/www.sxr666.cn\/index.php\/wp-json\/wp\/v2\/posts\/373"}],"collection":[{"href":"https:\/\/www.sxr666.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sxr666.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sxr666.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sxr666.cn\/index.php\/wp-json\/wp\/v2\/comments?post=373"}],"version-history":[{"count":25,"href":"https:\/\/www.sxr666.cn\/index.php\/wp-json\/wp\/v2\/posts\/373\/revisions"}],"predecessor-version":[{"id":637,"href":"https:\/\/www.sxr666.cn\/index.php\/wp-json\/wp\/v2\/posts\/373\/revisions\/637"}],"wp:attachment":[{"href":"https:\/\/www.sxr666.cn\/index.php\/wp-json\/wp\/v2\/media?parent=373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sxr666.cn\/index.php\/wp-json\/wp\/v2\/categories?post=373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sxr666.cn\/index.php\/wp-json\/wp\/v2\/tags?post=373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}