{"id":6512,"date":"2024-03-20T08:01:01","date_gmt":"2024-03-20T00:01:01","guid":{"rendered":""},"modified":"2024-03-20T08:01:01","modified_gmt":"2024-03-20T00:01:01","slug":"\u7ebf\u6027\u8868-\u94fe\u5f0f\u5b58\u50a8(\u5934\u63d2\u4e0e\u5c3e\u63d2)","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6512.html","title":{"rendered":"\u7ebf\u6027\u8868-\u94fe\u5f0f\u5b58\u50a8(\u5934\u63d2\u4e0e\u5c3e\u63d2)"},"content":{"rendered":"

\u5bf9\u5934\u6307\u9488\u6982\u5ff5\u7684\u7406\u89e3\uff0c\u8fd9\u4e2a\u5f88\u91cd\u8981\u3002\u201c\u94fe\u8868\u4e2d\u7b2c\u4e00\u4e2a\u7ed3\u70b9\u7684\u5b58\u50a8\u4f4d\u7f6e\u53eb\u505a\u5934\u6307\u9488\u201d\uff0c\u5982\u679c\u94fe\u8868\u6709\u5934\u7ed3\u70b9\uff0c\u90a3\u4e48\u5934\u6307\u9488\u5c31\u662f\u6307\u5411\u5934\u7ed3\u70b9\u6570\u636e\u57df\u7684\u6307\u9488\u3002\u753b\u4e00\u4e2a\u56fe\u5427\u3002<\/span><\/span><\/span><\/p>\n

\n

\"\u7ebf\u6027\u8868-\u94fe\u5f0f\u5b58\u50a8(\u5934\u63d2\u4e0e\u5c3e\u63d2)\u200b<\/p>\n<\/div>\n

\u5934\u7ed3\u70b9\u662f\u4e3a\u4e86\u64cd\u4f5c\u7684\u7edf\u4e00\u4e0e\u65b9\u4fbf\u800c\u8bbe\u7acb\u7684\uff0c\u653e\u5728\u7b2c\u4e00\u4e2a\u5143\u7d20\u7ed3\u70b9\u4e4b\u524d\uff0c<\/span>\u5176\u6570\u636e\u57df\u4e00\u822c\u65e0\u610f\u4e49<\/span>\uff08\u5f53\u7136\u6709\u4e9b\u60c5\u51b5\u4e0b\u4e5f\u53ef\u5b58\u653e\u94fe\u8868\u7684\u957f\u5ea6\u3001\u7528\u505a\u76d1\u89c6\u54e8\u7b49\u7b49\uff09\u3002<\/span><\/p>\n

\u6709\u4e86\u5934\u7ed3\u70b9\u540e\uff0c\u5bf9\u5728\u7b2c\u4e00\u4e2a\u5143\u7d20\u7ed3\u70b9\u524d\u63d2\u5165\u7ed3\u70b9\u548c\u5220\u9664\u7b2c\u4e00\u4e2a\u7ed3\u70b9\uff0c\u5176\u64cd\u4f5c\u4e0e\u5bf9\u5176\u5b83\u7ed3\u70b9\u7684\u64cd\u4f5c\u7edf\u4e00\u4e86\u3002<\/span><\/p>\n

\u9996\u5143\u7ed3\u70b9\u4e5f\u5c31\u662f\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u7ed3\u70b9\uff0c\u5b83\u662f\u5934\u7ed3\u70b9\u540e\u8fb9\u7684\u7b2c\u4e00\u4e2a\u7ed3\u70b9\u3002<\/span><\/p>\n

\u5934\u7ed3\u70b9\u4e0d\u662f\u94fe\u8868\u6240\u5fc5\u9700\u7684\u3002<\/span><\/p>\n

\u5728\u7ebf\u6027\u8868\u7684\u94fe\u5f0f\u5b58\u50a8\u7ed3\u6784\u4e2d\uff0c\u5934\u6307\u9488\u662f\u6307\u94fe\u8868\u6307\u5411\u7b2c\u4e00\u4e2a\u7ed3\u70b9\u7684\u6307\u9488\uff0c\u82e5\u94fe\u8868\u6709\u5934\u7ed3\u70b9\uff0c\u5219\u5934\u6307\u9488\u5c31\u662f\u6307\u5411\u94fe\u8868\u5934\u7ed3\u70b9\u7684\u6307\u9488\u3002<\/span><\/p>\n

\u5934\u6307\u9488\u5177\u6709\u6807\u8bc6\u4f5c\u7528\uff0c\u6545\u5e38\u7528\u5934\u6307\u9488\u51a0\u4ee5\u94fe\u8868\u7684\u540d\u5b57\u3002<\/span><\/p>\n

\u65e0\u8bba\u94fe\u8868\u662f\u5426\u4e3a\u7a7a\uff0c\u5934\u6307\u9488\u5747\u4e0d\u4e3a\u7a7a\u3002\u5934\u6307\u9488<\/span>\u662f\u94fe\u8868\u7684\u5fc5\u8981\u5143\u7d20\u3002<\/span><\/span><\/p>\n

\n

\u5355\u94fe\u8868\u4e5f\u53ef\u4ee5\u6ca1\u6709\u5934\u7ed3\u70b9\u3002\u5982\u679c\u6ca1\u6709\u5934\u7ed3\u70b9\u7684\u8bdd\uff0c\u90a3\u4e48\u5355\u94fe\u8868\u5c31\u4f1a\u53d8\u6210\u8fd9\u6837\uff1a<\/span><\/span><\/span><\/p>\n

\n

\"\u7ebf\u6027\u8868-\u94fe\u5f0f\u5b58\u50a8(\u5934\u63d2\u4e0e\u5c3e\u63d2)\u200b<\/p>\n<\/div>\n

------------------------------------------------------------------------------------------------------------------<\/span><\/p>\n

\u5355\u94fe\u8868\u6574\u8868\u521b\u5efa\u7684\u7b97\u6cd5\u601d\u8def\uff1a<\/span><\/p>\n

    \n
  1. \u58f0\u660e\u4e00\u7ed3\u70b9p\u548c\u8ba1\u6570\u5668\u53d8\u91cfi\uff1b<\/li>\n
  2. \u521d\u59cb\u5316\u4e00\u7a7a\u94fe\u8868L\uff1b<\/li>\n
  3. \u8ba9L\u7684\u5934\u7ed3\u70b9\u7684\u6307\u9488\u6307\u5411NULL,\u5373\u5efa\u7acb\u4e00\u4e2a\u5e26\u5934\u7ed3\u70b9\u7684\u5355\u94fe\u8868\uff1b<\/li>\n
  4. \u5faa\u73af\uff1a<\/li>\n
  5. \u751f\u6210\u4e00\u65b0\u7ed3\u70b9\u8d4b\u503c\u7ed9p;<\/li>\n
  6. \u968f\u673a\u751f\u6210\u4e00\u6570\u5b57\u8d4b\u503c\u7ed9P\u7684\u6570\u636e\u57dfp->data;<\/li>\n
  7. \u5c06p\u63d2\u5165\u5230\u5934\u7ed3\u70b9\u4e0e\u524d\u4e00\u65b0\u7ed3\u70b9\u4e4b\u95f4\u3002<\/li>\n<\/ol>\n

    \u5934\u63d2\u6cd5\u521b\u5efa\u94fe\u8868<\/span><\/p>\n

    \/\/\u5934\u63d2\u6cd5\u521b\u5efa\u94fe\u8868\u7684\u51fd\u6570
    void CreateListHead(LinkList *L, int n)
    {
    \n <\/span><\/p>\n

    \/\/\u58f0\u660e\u4e00\u7ed3\u70b9p\u548c\u8ba1\u6570\u5668\u53d8\u91cfi
        LinkList p;
        int i;
        srand(time(0)); \/\/\u521d\u59cb\u5316\u968f\u673a\u6570\u79cd\u5b50<\/span><\/p>\n

    \/\/\u521d\u59cb\u5316\u4e00\u7a7a\u94fe\u8868L\uff0c\u8ba9L\u7684\u5934\u7ed3\u70b9\u7684\u6307\u9488\u6307\u5411NULL,\u5373\u5efa\u7acb\u4e00\u4e2a\u5e26\u5934\u7ed3\u70b9\u7684\u5355\u94fe\u8868
        *L = (LinkList)malloc(sizeof(Node));\/\/\u5f00\u8f9f\u4e00\u4e2aL\u7ed3\u6784\u5927\u5c0f\u7684\u5185\u5b58\u5730\u5740<\/span>
        (*L)->next = NULL;\/\/\u5148\u5efa\u7acb\u4e00\u4e2a\u5e26\u5934\u7ed3\u70b9\u7684\u5355\u94fe\u8868<\/span><\/span><\/p>\n

        for (i=0; i < n; i++)
        {
    \n
            p = (LinkList)malloc(sizeof(Node)); \/\/\u751f\u6210\u65b0\u7ed3\u70b9<\/span>
            p->data = rand() % 100 + 1; \/\/ \u968f\u673a\u751f\u6210100\u4ee5\u5185\u7684\u6570\u5b57<\/span><\/p>\n

            p->next = (*L)->next;\/\/ \u6307\u5411\u4e0b\u4e00\u4e2a
            (*L)->next = p;\/\/ \u63d2\u5165\u5230\u8868\u5934<\/span>
         }
    }
    1. \u9996\u5148\u7528 *L = (LinkList)malloc(sizeof(Node)); \u4ea7\u751f\u5934\u7ed3\u70b9\uff0c\u5e76\u4f7fL\u6307\u5411\u6b64\u5934\u7ed3\u70b9\u3002\u518d\u7528 (*L)->next = NULL; \u5373\u53ef\u521b\u5efa\u4e00\u4e2a\u5e26\u5934\u7ed3\u70b9\u7684\u7a7a\u94fe\u8868\u3002<\/span><\/span><\/p>\n

    2. \u63a5\u4e0b\u6765\u5c31\u662f\u5faa\u73af\u5566\u3002\u65b0\u589e\u7ed3\u70b9\u90fd\u9700\u8981\u7528 (LinkList)malloc(sizeof(Node)); \u6765\u5f00\u8f9f\u5185\u5b58\u7a7a\u95f4\u3002<\/span>\u751f\u6210\u7ed3\u70b9 p \u4e4b\u540e\u5c31\u7ed9 p \u7684 data \u8d4b\u968f\u673a\u503c\uff0c\u7136\u540e\u518d\u7ed9 p \u7684 next \u8d4b\u503c\u3002\u753b\u4e2a\u56fe\u5c31\u5f88\u6e05\u6670\u4e86\uff1a<\/span><\/p>\n

    \n

    \"\u7ebf\u6027\u8868-\u94fe\u5f0f\u5b58\u50a8(\u5934\u63d2\u4e0e\u5c3e\u63d2)\u200b<\/p>\n<\/div>\n

    \u5b8c\u6574\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\uff08\u4fee\u590d\u63d2\u5165\u64cd\u4f5c\u7684\u51fd\u6570\uff09\uff1a<\/span><\/p>\n

    #include \"stdio.h\"\n\n#define OK 1\n#define ERROR 0\n#define TRUE 1\n#define FALSE 0\n\n#define MAXSIZE 20 \/\/ \u5b58\u50a8\u7a7a\u95f4\u521d\u59cb\u5206\u914d\u91cf\n\ntypedef int Status;\/\/ Status\u662f\u51fd\u6570\u7684\u7c7b\u578b,\u5176\u503c\u662f\u51fd\u6570\u7ed3\u679c\u72b6\u6001\u4ee3\u7801\uff0c\u5982OK\u7b49\ntypedef int ElemType;\/\/ ElemType\u7c7b\u578b\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u800c\u5b9a\uff0c\u8fd9\u91cc\u5047\u8bbe\u4e3aint\n\n\/\/\n\ntypedef struct Node \/\/\u4e3a\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u7c7b\u578b\u5b9a\u4e49\u4e00\u4e2a\u65b0\u540d\u5b57Node\n{\n    ElemType data; \n    struct Node *next; \n\n}Node;\ntypedef struct Node *LinkList; \/\/ \u5b9a\u4e49LinkList\u7ed3\u6784\u6307\u9488\uff0c\u7b49\u540c\u4e8etypedef (struct Node *) LinkList<\/code><\/pre>\n

    \u76f8\u5173\u89e3\u91ca\uff1a<\/span><\/p>\n

    https:\/\/zhidao.baidu.com\/question\/480523838.html?qbl=relate_question_0&word=Node a; struct node a; struct node<\/span><\/p>\n

    typedef struct node { int data; struct node *next; }Node,*LinkList;<\/strong>
    \u8fd9\u662f\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\uff0c\u8fd9\u4e2a\u7ed3\u6784\u4f53\u6709\u4e24\u4e2a\u5c5e\u6027\uff0c\u4e00\u4e2a\u662fint\u7c7b\u578b\u7684data\u3002\u53e6\u4e00\u4e2a\u662f\u8fd9\u4e2a\u7ed3\u6784\u4f53\u672c<\/span>\u8eab\u7c7b\u578b\u7684\u6307\u9488next\u3002\u7ed9\u8fd9\u4e2a\u7ed3\u6784\u5b9a\u4e49\u4e86\u4e00\u4e2a\u522b\u540d:Node\uff0c\u4e00\u4e2a\u6307\u9488\u522b\u540d:LinkList\u3002
    Node a;  \u7b49\u4ef7\u4e8e  struct node a;  \u90fd\u662f\u58f0\u660e\u4e00\u4e2astruct node\u7ed3\u6784\u4f53\u7c7b\u578b\u7684\u7ed3\u6784\u4f53\u53d8\u91cf a<\/span>\u3002
    LinkList b;   \u7b49\u4ef7\u4e8e  struct node *b;  \u7b49\u4ef7\u4e8e Node *b;    \u58f0\u660e\u4e00\u4e2astruct node\u7ed3\u6784\u4f53<\/span><\/span>\u7c7b\u578b\u7684\u6307\u9488\u53d8\u91cf b<\/span>\u3002
    \/\/<\/p>\n

    \/\/\u4ece\u8fd9\u4e2a\u7ed3\u6784\u5b9a\u4e49\u4e2d\uff0c\u7ed3\u70b9\u7531\u5b58\u653e\u6570\u636e\u5143\u7d20\u7684\u6570\u636e\u57df\u548c\u5b58\u653e\u540e\u7ee7\u7ed3\u70b9\u5730\u5740\u7684\u6307\u9488\u57df\u7ec4\u6210\u3002<\/span><\/p>\n

    \/\/\u5047\u8bbep\u662f\u6307\u5411\u7ebf\u6027\u8868\u7b2ci\u4e2a\u5143\u7d20\u7684\u6307\u9488\uff0c\u5219\u8be5\u7ed3\u70b9ai\u7684\u6570\u636e\u57df\u6211\u4eec\u53ef\u4ee5\u7528p->data\u6765\u8868\u793a\uff0cp->data<\/span><\/p>\n

    \/\/\u7684\u503c\u662f\u4e00\u4e2a\u6570\u636e\u5143\u7d20\uff0c\u7ed3\u70b9ai\u7684\u6307\u9488\u57df\u53ef\u4ee5\u7528 p->next\u6765\u8868\u793a\uff0cp->next\u7684\u503c\u662f\u4e00\u4e2a\u6307\u9488\u3002<\/span><\/p>\n

    \/\/p->next\u6307\u5411\u8c01\u5462\uff1f\u5f53\u7136\u662f\u6307\u5411\u7b2ci+1\u4e2a\u5143\u7d20\uff0c\u5373\u6307\u5411ai+1\u7684\u6307\u9488\u3002<\/span><\/p>\n<\/p>\n

    \/\/ \u521d\u59cb\u5316\u987a\u5e8f\u7ebf\u6027\u8868\uff0c\u5b9e\u53c2\u8981\u6539\u53d8\u5c31\u8981\u4f20\u5730\u5740\uff0c\u5426\u5219\u4f20\u503c
    Status InitList(LinkList *L) \/\/\u53c2\u6570*L\u4f20\u5165\u7684L\u5176\u5b9e\u5c31\u662f\u94fe\u8868\u7684\u9996\u5730\u5740\uff0c\u4e5f\u5c31\u662f\u5934\u6307\u9488<\/span><\/span>
    {                   \/\/LinkList *L\u7b49\u540c\u4e8estruct Node **L\uff0c**L\u5c31\u662f\u53d8\u91cf\uff0c*L\u5c31\u662f\u6307\u9488\uff0cL\u5c31\u662f\u6307\u5411\u6307\u9488\u7684\u6307\u9488<\/span>
        *L=(LinkList)malloc(sizeof(Node)); \/\/ \u4ea7\u751f\u5934\u7ed3\u70b9,\u5e76\u4f7fL\u6307\u5411\u6b64\u5934\u7ed3\u70b9<\/span><\/p>\n

        \/\/L\u662f\u4e2a\u6307\u9488\uff0c\u6307\u5411\u5934\u7ed3\u70b9\uff0c*L\u5c31\u662f\u6307\u5934\u7ed3\u70b9\u3002<\/span><\/span>
        if(!(*L)) \/\/ \u5b58\u50a8\u5206\u914d\u5931\u8d25
        {
    \n
            return ERROR;
        }
        (*L)->next=NULL; \/\/ \u6307\u9488\u57df\u4e3a\u7a7a <\/span><\/p>\n

    \/\/\u56e0\u4e3a *L\u662f\u5934\u7ed3\u70b9\uff0c\u90a3\u4e48 (*L)->next\u5c31\u662f\u9996\u5143\u7ed3\u70b9\uff0c\u6240\u4ee5 (*L)->next=NULL;<\/span><\/span><\/span><\/p>\n

    \/\/\u8fd9\u4e48\u5199\u5c31\u80fd\u8ba9\u9996\u5143\u7ed3\u70b9\u7684\u6307\u9488\u57df\u4e3a\u7a7a<\/span><\/span><\/span><\/p>\n

        return OK;
    }<\/span><\/p>\n

     \/\/ \u521d\u59cb\u6761\u4ef6\uff1a\u987a\u5e8f\u7ebf\u6027\u8868L\u5df2\u5b58\u5728\u3002\u64cd\u4f5c\u7ed3\u679c\uff1a\u8fd4\u56deL\u4e2d\u6570\u636e\u5143\u7d20\u4e2a\u6570<\/span><\/p>\n

    int ListLength(LinkList L)\n{\n    int i=0;\n    LinkList p=L->next; \/\/ p\u6307\u5411\u7b2c\u4e00\u4e2a\u7ed3\u70b9\n\n    while(p)\n    {\n        i++;\n        p=p->next;\n    }\n    return i;\n}<\/code><\/pre>\n

    \/\/ \u521d\u59cb\u6761\u4ef6\uff1a\u987a\u5e8f\u7ebf\u6027\u8868L\u5df2\u5b58\u5728
    \/\/ \u64cd\u4f5c\u7ed3\u679c\uff1a\u4f9d\u6b21\u5bf9L\u7684\u6bcf\u4e2a\u6570\u636e\u5143\u7d20\u8f93\u51fa<\/span><\/p>\n

    Status ListTraverse(LinkList L)\n{\n    LinkList p=L->next;\n\n    while(p)\n    {\n        visit(p->data);\n        p=p->next;\n    }\n    printf(\"\\n\");\n    return OK;\n}\n\nStatus visit(ElemType c)\n{\n    printf(\"-> %d \",c);\n    return OK;\n}<\/code><\/pre>\n

    \/\/\u5b9e\u53c2\u8981\u6539\u53d8\u5c31\u8981\u4f20\u5730\u5740\uff0c\u5426\u5219\u4f20\u503c\/\/ \u521d\u59cb\u6761\u4ef6\uff1a\u987a\u5e8f\u7ebf\u6027\u8868L\u5df2\u5b58\u5728\uff0c1\u2264i\u2264ListLength(L)
    \/\/ \u64cd\u4f5c\u7ed3\u679c\uff1a\u7528e\u8fd4\u56deL\u4e2d\u7b2ci\u4e2a\u6570\u636e\u5143\u7d20\u7684\u503c<\/span><\/p>\n

    Status GetElem(LinkList L,int i,ElemType *e)\n{\n int j;\n LinkList p;  \/\/ \u58f0\u660e\u4e00\u7ed3\u70b9p\n p = L->next;  \/\/ \u8ba9p\u6307\u5411\u94fe\u8868L\u7684\u7b2c\u4e00\u4e2a\u7ed3\u70b9\n j = 1;  \/\/  j\u4e3a\u8ba1\u6570\u5668\n\n while (p && j < i)  \/\/ p\u4e0d\u4e3a\u7a7a\u6216\u8005\u8ba1\u6570\u5668j\u8fd8\u6ca1\u6709\u7b49\u4e8ei\u65f6\uff0c\u5faa\u73af\u7ee7\u7eed\n {\n  p = p->next;  \/\/ \u8ba9p\u6307\u5411\u4e0b\u4e00\u4e2a\u7ed3\u70b9\n  ++j;\n }\n if ( !p || j>i )\n  return ERROR;  \/\/  \u7b2ci\u4e2a\u5143\u7d20\u4e0d\u5b58\u5728\n *e = p->data;   \/\/  \u53d6\u7b2ci\u4e2a\u5143\u7d20\u7684\u6570\u636e\n return OK;\n}<\/code><\/pre>\n

    \/\/ \u521d\u59cb\u6761\u4ef6\uff1a\u987a\u5e8f\u7ebf\u6027\u8868L\u5df2\u5b58\u5728
    \/\/ \u64cd\u4f5c\u7ed3\u679c\uff1a\u8fd4\u56deL\u4e2d\u7b2c1\u4e2a\u4e0ee\u6ee1\u8db3\u5173\u7cfb\u7684\u6570\u636e\u5143\u7d20\u7684\u4f4d\u5e8f\u3002
    \/\/ \u82e5\u8fd9\u6837\u7684\u6570\u636e\u5143\u7d20\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u503c\u4e3a0<\/span><\/p>\n

    int LocateElem(LinkList L,ElemType e)\n{\n    int i=0;\n    LinkList p=L->next;\n\n    while(p)\n    {\n        i++;\n        if(p->data==e) \/\/ \u627e\u5230\u8fd9\u6837\u7684\u6570\u636e\u5143\u7d20\n                return i;\n        p=p->next;\n    }\n\n    return 0;\n}<\/code><\/pre>\n

    \/\/\/\u968f\u673a\u4ea7\u751fn\u4e2a\u5143\u7d20\u7684\u503c\uff0c\u5efa\u7acb\u5e26\u8868\u5934\u7ed3\u70b9\u7684\u5355\u94fe\u7ebf\u6027\u8868L\uff08\u5934\u63d2\u6cd5\uff09\/\/\/<\/span><\/p>\n

    void CreateListHead(LinkList *L, int n)\n{\n LinkList p;\n int i;\n\n srand(time(0));                         \/\/ \u521d\u59cb\u5316\u968f\u673a\u6570\u79cd\u5b50\n *L = (LinkList)malloc(sizeof(Node));\n (*L)->next = NULL;                  \/\/ \u5148\u5efa\u7acb\u4e00\u4e2a\u5e26\u5934\u7ed3\u70b9\u7684\u5355\u94fe\u8868\n for (i=0; i < n; i++)\n {\n    p = (LinkList)malloc(sizeof(Node)); \/\/  \u751f\u6210\u65b0\u7ed3\u70b9\n    p->data = rand() % 100+1;          \/\/  \u968f\u673a\u751f\u6210100\u4ee5\u5185\u7684\u6570\u5b57\n    p->next = (*L)->next;\n    (*L)->next = p;      \/\/  \u63d2\u5165\u5230\u8868\u5934\n }\n}<\/code><\/pre>\n

    \/\/\/\u968f\u673a\u4ea7\u751fn\u4e2a\u5143\u7d20\u7684\u503c\uff0c\u5efa\u7acb\u5e26\u8868\u5934\u7ed3\u70b9\u7684\u5355\u94fe\u7ebf\u6027\u8868L\uff08\u5c3e\u63d2\u6cd5\uff09\/\/\/<\/span><\/p>\n

    void CreateListTail(LinkList *L, int n)\n{\n LinkList p,r;\n int i;\n\n srand(time(0));                      \/\/ \u521d\u59cb\u5316\u968f\u673a\u6570\u79cd\u5b50\n *L = (LinkList)malloc(sizeof(Node)); \/\/ L\u4e3a\u6574\u4e2a\u7ebf\u6027\u8868\n r=*L;                                \/\/ r\u4e3a\u6307\u5411\u5c3e\u90e8\u7684\u7ed3\u70b9\n\n\n for (i=0; i < n; i++)\n {\n    p = (Node *)malloc(sizeof(Node)); \/\/  \u751f\u6210\u65b0\u7ed3\u70b9\n    p->data = rand() % 100+1;           \/\/  \u968f\u673a\u751f\u6210100\u4ee5\u5185\u7684\u6570\u5b57\n    r->next=p;                        \/\/ \u5c06\u8868\u5c3e\u7ec8\u7aef\u7ed3\u70b9\u7684\u6307\u9488\u6307\u5411\u65b0\u7ed3\u70b9\n    r = p;                            \/\/ \u5c06\u5f53\u524d\u7684\u65b0\u7ed3\u70b9\u5b9a\u4e49\u4e3a\u8868\u5c3e\u7ec8\u7aef\u7ed3\u70b9\n }\n r->next = NULL;                       \/\/ \u8868\u793a\u5f53\u524d\u94fe\u8868\u7ed3\u675f\n}<\/code><\/pre>\n

    \/\/ \u521d\u59cb\u6761\u4ef6\uff1a\u987a\u5e8f\u7ebf\u6027\u8868L\u5df2\u5b58\u5728,1\u2264i\u2264ListLength(L)\uff0c
    \/\/ \u64cd\u4f5c\u7ed3\u679c\uff1a\u5728L\u4e2d\u7b2ci\u4e2a\u4f4d\u7f6e\u4e4b\u524d\u63d2\u5165\u65b0\u7684\u6570\u636e\u5143\u7d20e\uff0cL\u7684\u957f\u5ea6\u52a01<\/span><\/p>\n

    Status ListInsert(LinkList *L,int i,ElemType e)\n{\n int j;\n LinkList p,s;\n\n p = *L;     \/\/ \u58f0\u660e\u4e00\u4e2a\u7ed3\u70b9 p\uff0c\u6307\u5411\u5934\u7ed3\u70b9\n j = 1;\n\n while (p && j < i)     \/\/ \u5bfb\u627e\u7b2ci\u4e2a\u7ed3\u70b9\n {\n    p = p->next;\n    ++j;\n }\n\n if (!p || j > i)\n    return ERROR;   \/\/ \u7b2ci\u4e2a\u5143\u7d20\u4e0d\u5b58\u5728\n\n s = (LinkList)malloc(sizeof(Node));  \/\/  \u751f\u6210\u65b0\u7ed3\u70b9(C\u8bed\u8a00\u6807\u51c6\u51fd\u6570)\n s->data = e;\n s->next = p->next;      \/\/ \u5c06p\u7684\u540e\u7ee7\u7ed3\u70b9\u8d4b\u503c\u7ed9s\u7684\u540e\u7ee7 \n p->next = s;          \/\/ \u5c06s\u8d4b\u503c\u7ed9p\u7684\u540e\u7ee7\n return OK;\n}<\/code><\/pre>\n

    \/\/ \u521d\u59cb\u6761\u4ef6\uff1a\u987a\u5e8f\u7ebf\u6027\u8868L\u5df2\u5b58\u5728\uff0c1\u2264i\u2264ListLength(L)
    \/\/ \u64cd\u4f5c\u7ed3\u679c\uff1a\u5220\u9664L\u7684\u7b2ci\u4e2a\u6570\u636e\u5143\u7d20\uff0c\u5e76\u7528e\u8fd4\u56de\u5176\u503c\uff0cL\u7684\u957f\u5ea6\u51cf1<\/span><\/p>\n

    Status ListDelete(LinkList *L,int i,ElemType *e)\n{\n int j;\n LinkList p,q;\n\n p = *L;\n j = 1;\n\n while (p->next && j < i) \/\/ \u904d\u5386\u5bfb\u627e\u7b2ci\u4e2a\u5143\u7d20\n {\n        p = p->next;\n        ++j;\n }\n if (!(p->next) || j > i)\n     return ERROR;           \/\/ \u7b2ci\u4e2a\u5143\u7d20\u4e0d\u5b58\u5728\n q = p->next;\n p->next = q->next;   \/\/ \u5c06q\u7684\u540e\u7ee7\u8d4b\u503c\u7ed9p\u7684\u540e\u7ee7\n *e = q->data;               \/\/ \u5c06q\u7ed3\u70b9\u4e2d\u7684\u6570\u636e\u7ed9e\n free(q);                    \/\/ \u8ba9\u7cfb\u7edf\u56de\u6536\u6b64\u7ed3\u70b9\uff0c\u91ca\u653e\u5185\u5b58\n return OK;\n}\n\nint main()\n{\n    LinkList L; \/\/L\u662f\u7ed3\u6784\u4f53\u6307\u9488\n    Status i;\n    int j,k,pos,value;\n    char opp;\n    ElemType e;\n\n    i=InitList(&L);  \/\/\u53c2\u6570*L\u4f20\u5165\u7684L\u5176\u5b9e\u5c31\u662f\u94fe\u8868\u7684\u9996\u5730\u5740\uff0c\u4e5f\u5c31\u662f\u5934\u6307\u9488\n    printf(\"\u94fe\u8868L\u521d\u59cb\u5316\u5b8c\u6bd5\uff0cListLength(L)=%d\\n\",ListLength(L));\n\n    printf(\"\\n1.\u6574\u8868\u521b\u5efa\uff08\u5934\u63d2\u6cd5\uff09 \\n2.\u6574\u8868\u521b\u5efa\uff08\u5c3e\u63d2\u6cd5\uff09 \\n3.\u904d\u5386\u64cd\u4f5c \\n4.\u63d2\u5165\u64cd\u4f5c \\n5.\u5220\u9664\u64cd\u4f5c \\n6.\u83b7\u53d6\u7ed3\u70b9\u6570\u636e \\n7.\u67e5\u627e\u67d0\u4e2a\u6570\u662f\u5426\u5728\u94fe\u8868\u4e2d \\n0.\u9000\u51fa \\n\u8bf7\u9009\u62e9\u4f60\u7684\u64cd\u4f5c\uff1a\\n\");\n    while(opp != '0'){\n        scanf(\"%c\",&opp);\n        switch(opp){\n            case '1':\n                CreateListHead(&L,10);\n                printf(\"\u6574\u4f53\u521b\u5efaL\u7684\u5143\u7d20(\u5934\u63d2\u6cd5)\uff1a\\n\");\n                ListTraverse(L);\n                printf(\"\\n\");\n                break;\n\n            case '2':\n                CreateListTail(&L,10);\n                printf(\"\u6574\u4f53\u521b\u5efaL\u7684\u5143\u7d20(\u5c3e\u63d2\u6cd5)\uff1a\\n\");\n                ListTraverse(L);\n                printf(\"\\n\");\n                break;\n\n            case '3':\n                ListTraverse(L);\n                printf(\"\\n\");\n                break;\n\n            case '4':\n                printf(\"\u8981\u5728\u7b2c\u51e0\u4e2a\u4f4d\u7f6e\u63d2\u5165\u5143\u7d20\uff1f\");\n                scanf(\"%d\",&pos);\n                printf(\"\u63d2\u5165\u7684\u5143\u7d20\u503c\u662f\u591a\u5c11\uff1f\");\n                scanf(\"%d\",&value);\n                ListInsert(&L,pos,value);\n                ListTraverse(L);\n                printf(\"\\n\");\n                break;\n\n            case '5':\n                printf(\"\u8981\u5220\u9664\u7b2c\u51e0\u4e2a\u5143\u7d20\uff1f\");\n                scanf(\"%d\",&pos);\n                ListDelete(&L,pos,&e);\n                printf(\"\u5220\u9664\u7b2c%d\u4e2a\u5143\u7d20\u6210\u529f\uff0c\u73b0\u5728\u94fe\u8868\u4e3a\uff1a\\n\", pos);\n                ListTraverse(L);\n                printf(\"\\n\");\n                break;\n\n            case '6':\n                printf(\"\u4f60\u9700\u8981\u83b7\u53d6\u7b2c\u51e0\u4e2a\u5143\u7d20\uff1f\");\n                scanf(\"%d\",&pos);\n                GetElem(L,pos,&e);\n                printf(\"\u7b2c%d\u4e2a\u5143\u7d20\u7684\u503c\u4e3a\uff1a%d\\n\", pos, e);\n                printf(\"\\n\");\n                break;\n\n            case '7':\n                printf(\"\u8f93\u5165\u4f60\u9700\u8981\u67e5\u627e\u7684\u6570\uff1a\");\n                scanf(\"%d\",&pos);\n                k=LocateElem(L,pos);\n                if(k)\n                    printf(\"\u7b2c%d\u4e2a\u5143\u7d20\u7684\u503c\u4e3a%d\\n\",k,pos);\n                else\n                    printf(\"\u6ca1\u6709\u503c\u4e3a%d\u7684\u5143\u7d20\\n\",pos);\n                printf(\"\\n\");\n                break;\n\n            case '0':\n                exit(0);\n        }\n    }\n\n}<\/code><\/pre>\n

    \u5c3e\u63d2\u6cd5\u521b\u5efa\u94fe\u8868<\/span><\/p>\n

    \u6211\u4eec\u628a\u6bcf\u6b21\u65b0\u7ed3\u70b9\u90fd\u63d2\u5728\u7ec8\u7aef\u7ed3\u70b9\u7684\u540e\u9762\uff0c\u8fd9\u79cd\u7b97\u6cd5\u79f0\u4e4b\u4e3a\u5c3e\u63d2\u6cd5\u3002
    \/\/\u968f\u673a\u4ea7\u751fn\u4e2a\u5143\u7d20\u7684\u503c\uff0c\u5efa\u7acb\u5e26\u8868\u5934\u7ed3\u70b9\u7684\u5355\u94fe\u7ebf\u6027\u8868L\uff08\u5c3e\u63d2\u6cd5\uff09<\/span><\/p>\n

    void CreateListTail(LinkList *L, int n)\n{\n  LinkList p,r;\n  int i;\n  srand(time(0));   \/\/\u521d\u59cb\u5316\u968f\u673a\u6570\u79cd\u5b50\n  *L = (LinkList)malloc(sizeof(Node)); \/\/L\u4e3a\u6574\u4e2a\u7ebf\u6027\u8868\n  r=*L;                   \/\/r\u4e3a\u6307\u5411\u5c3e\u90e8\u7684\u7ed3\u70b9\n  for (i=0; i < n; i++)\n  {\n    p = (Node *)malloc(sizeof(Node));  \/\/ \u751f\u6210\u65b0\u7ed3\u70b9\n    p->data = rand() % 100+1;   \/\/\u968f\u673a\u751f\u6210100\u4ee5\u5185\u7684\u6570\u5b57\n    r->next=p;  \/\/\u5c06\u8868\u5c3e\u7ec8\u7aef\u7ed3\u70b9\u7684\u6307\u9488\u6307\u5411\u65b0\u7ed3\u70b9\n    r = p;           \/\/\u5c06\u5f53\u524d\u7684\u65b0\u7ed3\u70b9\u5b9a\u4e49\u4e3a\u8868\u5c3e\u7ec8\u7aef\u7ed3\u70b9\n  }\n  r->next = NULL;     \/\/\u8868\u793a\u5f53\u524d\u94fe\u8868\u7ed3\u675f\n}\n<\/code><\/pre>\n

    \u4e0e\u5934\u63d2\u6cd5\u533a\u522b\u4e0b\uff1f *L \u662f\u5934\u7ed3\u70b9\uff0cr\u8fd9\u91cc\u7684\u89d2\u8272\u662f\u5c3e\u7ed3\u70b9\uff0c\u4e00\u5f00\u59cb\u4ed6\u4eec\u662f\u91cd\u5408\u7684\u3002<\/span><\/span><\/p>\n

    \u5bf9\uff0c\u7136\u540e\u6211\u4eec\u9700\u8981\u5728\u7ed3\u70b9 r \u7684\u540e\u9762\u63d2\u5165\u4e00\u4e2a\u7ed3\u70b9 p\u3002\u8fd9\u5f88\u7b80\u5355\uff0c\u5c06 r \u7684 next \u6307\u5411 p \u7ed3\u70b9\u5373\u53ef\u3002\u8fd9\u65f6\u8981\u6ce8\u610f\uff0c\u5f53\u5b8c\u6210 p \u7684\u63d2\u5165\u4e4b\u540e\uff0cp \u4f1a\u6210\u4e3a\u65b0\u7684 r\u3002\u5f53\u5b8c\u6210\u5faa\u73af\u4e4b\u540e\uff0cr->next = NULL; \u5c31\u5b8c\u6210\u8fd9\u4e2a\u5355\u94fe\u8868\u3002<\/span><\/p>\n

    r=p;\u662f\u8fd9\u4e2a\u610f\u601d\u5427\u3002\u5c31\u662f\u672c\u6765r\u662f\u5728\u5143\u7d20\u7684\u7ed3\u70b9\uff0c\u53ef\u73b0\u5728\u5b83\u5df2\u7ecf\u4e0d\u662f\u6700\u540e\u7684\u7ed3\u70b9\u4e86\uff0c\u73b0\u5728\u6700\u540e\u7684\u7ed3\u70b9\uff0c\u6240\u4ee5\u5e94\u8be5\u8981\u8ba9\u5c06p\u7ed3\u70b9\u8fd9\u4e2a\u6700\u540e\u7684\u7ed3\u70b9\u8d4b\u503c\u7ed9r\u3002\u6b64\u65f6r\u53c8\u662f\u6700\u7ec8\u7684\u5c3e\u7ed3\u70b9\u4e86\u3002\u5faa\u73af\u7ed3\u675f\u540e\uff0c\u90a3\u4e48\u5e94\u8be5\u8ba9\u8fd9\u4e2a\u94fe\u8868\u7684\u6307\u9488\u57df\u7f6e\u7a7a\uff0c\u56e0\u6b64\u6709\u4e86 r->next = NULL;   \u5b8c\u6574\u7684\u7a0b\u5e8f\u5982\u4e0a\u3002<\/span><\/p>\n

    ------------------------------------------------------------------------------------------------------------------<\/span>
    \u9644\u5f55<\/span><\/p>\n

    1\u3001\u53c2\u8003\uff1a\u7b2c01\u8bdd\uff1a\u7ebf\u6027\u8868\u7684\u6982\u5ff5\u4e0e\u5b9a\u4e49 -- \u7b80\u660e\u73b0\u4ee3\u9b54\u6cd5\u975e\u5e38\u597d<\/span><\/p>\n

    2\u3001\u53c2\u8003\uff1a\u5c0f\u7532\u9c7c\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd512_\u7ebf\u6027\u88687\uff08\u5b58\u4e8e\u6211\u7684\u767e\u5ea6\u4e91\u76d8\uff09<\/span><\/p>\n

    3\u3001\u7ed3\u6784\u4f53\u7684typedef<\/span><\/span><\/p>\n

    typedef struct Student<\/span>
    {
    \n <\/span>
      int a;<\/span>
    }Stu;<\/span>
    \u4e8e\u662f\u5728\u58f0\u660e\u53d8\u91cf\u7684\u65f6\u5019\u5c31\u53ef\uff1aStu stu1;<\/span>
    \u5982\u679c\u6ca1\u6709typedef\u5c31\u5fc5\u987b\u7528struct Student stu1;\u6765\u58f0\u660e<\/span>\uff0c\u8fd9\u91cc\u7684Stu\u5b9e\u9645\u4e0a\u5c31\u662fstruct Student\u7684\u522b\u540d\u3002<\/span>
    \u53e6\u5916\u8fd9\u91cc\u4e5f\u53ef\u4ee5\u4e0d\u5199Student\uff08\u4e8e\u662f\u4e5f\u4e0d\u80fdstruct Student stu1;\u4e86\uff09<\/span>
    typedef struct<\/span>
    {
    \n <\/span>
      int a;<\/span>
    }Stu;<\/span><\/span><\/span><\/p>\n

    ------------------------------------------------------------------------------------------------------------------<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"\u7ebf\u6027\u8868-\u94fe\u5f0f\u5b58\u50a8(\u5934\u63d2\u4e0e\u5c3e\u63d2)\u8be5\u6587\u7ae0\u4ecb\u7ecd\u4e86\u7ebf\u6027\u8868\u4e2d\u94fe\u5f0f\u5b58\u50a8\u7684\u5934\u6307\u9488\u6982\u5ff5\uff0c\u6307\u51fa\u5934\u6307\u9488\u6307\u5411\u94fe\u8868\u4e2d\u7b2c\u4e00\u4e2a\u7ed3\u70b9\u7684\u5b58\u50a8\u4f4d\u7f6e\uff0c\u82e5\u94fe\u8868...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6512"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6512"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6512\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}