<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 鏈表的類型 - 單鏈,雙鏈和循環鏈 > 原文: [https://www.programiz.com/dsa/linked-list-types](https://www.programiz.com/dsa/linked-list-types) #### 在本教程中,您將學習不同類型的鏈表。 此外,您還將在 C 中找到鏈表的實現。 鏈表有三種常見類型。 1. [單鏈表](#singly) 2. [雙鏈表](#doubly) 3. [循環鏈表](#circular) * * * ## 單鏈表 這是最常見的。 每個節點都有數據和指向下一個節點的指針。 ![singly linked list](https://img.kancloud.cn/a8/63/a863a1b7fe796e6effcb5801c40b06d7_1260x196.png "Singly linked list") 單鏈表 節點表示為: ``` struct node { int data; struct node *next; } ``` 可以將三個成員的單鏈表創建為: ``` /* Initialize nodes */ struct node *head; struct node *one = NULL; struct node *two = NULL; struct node *three = NULL; /* Allocate memory */ one = malloc(sizeof(struct node)); two = malloc(sizeof(struct node)); three = malloc(sizeof(struct node)); /* Assign data values */ one->data = 1; two->data = 2; three->data = 3; /* Connect nodes */ one->next = two; two->next = three; three->next = NULL; /* Save address of first node in head */ head = one; ``` * * * ## 雙鏈表 我們在雙向鏈表中添加一個指向前一個節點的指針。 因此,我們可以朝任一方向前進:前進或后退。 ![doubly linked list](https://img.kancloud.cn/46/28/46281c2c2d9934ffee0ee399f4df8d41_1614x196.png "Doubly linked list") 雙鏈表 節點表示為 ``` struct node { int data; struct node *next; struct node *prev; } ``` 可以創建一個三人雙向鏈表 ``` /* Initialize nodes */ struct node *head; struct node *one = NULL; struct node *two = NULL; struct node *three = NULL; /* Allocate memory */ one = malloc(sizeof(struct node)); two = malloc(sizeof(struct node)); three = malloc(sizeof(struct node)); /* Assign data values */ one->data = 1; two->data = 2; three->data = 3; /* Connect nodes */ one->next = two; one->prev = NULL; two->next = three; two->prev = one; three->next = NULL; three->prev = two; /* Save address of first node in head */ head = one; ``` * * * ## 循環鏈表 循環鏈表是鏈表的變體,其中最后一個元素鏈接到第一個元素。 這形成一個循環。 ![circular linked list](https://img.kancloud.cn/e7/37/e737690a155d2d2476ba8d311a988435_1156x244.png "Circular linked list") 循環鏈表 循環鏈表可以是單鏈或雙鏈。 * 對于單鏈表,最后一項的下一個指針指向第一個項 * 在雙向鏈表中,第一個項目的`prev`指針也指向最后一個項目。 可以將三元循環單鏈表創建為: ``` /* Initialize nodes */ struct node *head; struct node *one = NULL; struct node *two = NULL; struct node *three = NULL; /* Allocate memory */ one = malloc(sizeof(struct node)); two = malloc(sizeof(struct node)); three = malloc(sizeof(struct node)); /* Assign data values */ one->data = 1; two->data = 2; three->data = 3; /* Connect nodes */ one->next = two; two->next = three; three->next = one; /* Save address of first node in head */ head = one; ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看