老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

雙向循環鏈表詳解及C語言簡單實現-創新互聯

概念

鏈表是一種物理存儲結構上非連續、非順序的存儲結構,數據元素的邏輯順序是通過鏈表中的指針鏈接次序實現的。而雙向鏈表顧名思義通過指針域向前查找或者向后查找,且頭結點與尾節點直接相連構成環。
在這里插入圖片描述

創新互聯于2013年開始,是專業互聯網技術服務公司,擁有項目成都網站制作、成都做網站網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元孟村做網站,已為上家服務,為孟村各地企業和個人服務,聯系電話:18982081108數據結構
#ifndef DLIST_H
#define DLIST_H

// 數據類型,可根據需要自行定義
#define Item int 

// 鏈表節點信息 
typedef struct DLNode
{Item item;
    struct DLNode *prev;
    struct DLNode *next;
} DLNode;

typedef struct DList
{int size;
    DLNode *head;
} DList;

// Interfaces 
void InitDList(DList *dlist);
void InsertDlist(DList *dlist);
DLNode *searchDlist(Dlist *dlist);
void DeleteDlist(DList *dlist, const Item data);
void ShowDlist(const DList *dlist);
void freeDList(DList *dlist); 

#endif //DLIST_H
接口源代碼
#include#include#include#include

// 初始化雙向鏈表,帶頭結點
void InitDList(DList *dlist)
{dlist->head = (DLNode *)malloc(sizeof(DLNode));
    if (dlist->head == NULL)
        return;

    dlist->size = 0;
    dlist->head->item = -1;
    dlist->head->prev = dlist->head;
    dlist->head->next = dlist->head;
}

// 鏈表項數
int DListcounts(DList *dlist)
{assert(dlist);
    return dlist->size;
}

// 插入數據 1)將數據封裝成節點    2)插入鏈表尾
void InsertDList(DList *dlist, const Item data)
{assert(dlist != NULL);
    DLNode *newnode = (DLNode *)malloc(sizeof(DLNode));
    if(newnode == NULL)
    {printf("out of memory !!\n");
        exit(1);
    }

    newnode->item = data;

    newnode->prev = dlist->head->prev;
    newnode->next = dlist->head;
    dlist->head->prev->next = newnode;
    dlist->head->prev = newnode;
    dlist->size++;
}

// 在循環鏈表中查找指定數據的節點
DLNode *searchDList(DList *dlist, const Item data)
{int i;
    assert(dlist != NULL);
    if(dlist->size == 0)
    {printf("the dlist is empty, do not find element:%d\n", data);
        return NULL;
    }

    DLNode *cur = dlist->head->next;
    for (i = 0; i< dlist->size; i++)
    {if(cur->item == data)
        {printf("find it ^_^!!!\n");
            return cur;
        }
        cur = cur->next;
    }

    if( i == dlist->size)
    {printf("unlucky, the element:%d is not exist in dlsit\n");
        return NULL;
    }
}

// 在雙向循環鏈表中獲取指定數據的節點,并返回
void deleteDList(DList *dlist, const Item data)
{DLNode *node = searchDList(dlist, data);
    if(node == NULL)
    {printf("the delete element is not exist in dlist!!\n");
        return;
    }

    node->prev->next = node->next; 
    node->next->prev = node->prev;
    dlist->size--;
    free(node);
    printf("delete it successfully!!\n");
    return ;
}


// 釋放構建鏈表所申請的堆內存
void freeDList(DList *dlist)
{DLNode *cur =NULL, *next = NULL;
    for (cur = dlist->head->next; cur != dlist->head; cur = next)
    {next = cur->next;       // 獲取下一個節點
        free(cur);          // 釋放節點
    }

    free(dlist->head);
    dlist->head = NULL;
}
測試結果
// 主函數,對上述各接口調用
int main()
{DList list;
    DLNode *node;
    InitDList(&list);
    InsertDList(&list, 1);
    InsertDList(&list, 2);
    showDList(&list);
    node = searchDList(&list, 3);

    int counts1 = DListcounts(&list);
    printf("the counts of dlist is %d\n", counts1);

    deleteDList(&list, 1);

    int counts2 = DListcounts(&list);
    printf("the counts of dlist is %d\n", counts2);
    showDList(&list);
    freeDList(&list);
    return 0;
}

[postgres@test dlist_test]$ ./Dlist
1       2
unlucky, the element:3 is not exist in dlsit
the counts of dlist is 2
find it ^_^!!!
delete it successfully!!
the counts of dlist is 1
2
LeetCode 試題

在這里插入圖片描述

class Solution {public:
    Node* copyRandomList(Node* head) {if(head == nullptr) return nullptr;
        Node* cur = head;
        // 1. 復制各節點,并構建拼接鏈表
        while(cur != nullptr) {Node* tmp = new Node(cur->val);
            tmp->next = cur->next;
            cur->next = tmp;
            cur = tmp->next;
        }
        // 2. 構建各新節點的 random 指向
        cur = head;
        while(cur != nullptr) {if(cur->random != nullptr)
                cur->next->random = cur->random->next;
            cur = cur->next->next;
        }
        // 3. 拆分兩鏈表
        cur = head->next;
        Node* pre = head, *res = head->next;
        while(cur->next != nullptr) {pre->next = pre->next->next;
            cur->next = cur->next->next;
            pre = pre->next;
            cur = cur->next;
        }
        pre->next = nullptr; // 單獨處理原鏈表尾節點
        return res;      // 返回新鏈表頭節點
    }
};

你是否還在尋找穩定的海外服務器提供商?創新互聯www.cdcxhl.cn海外機房具備T級流量清洗系統配攻擊溯源,準確流量調度確保服務器高可用性,企業級服務器適合批量采購,新人活動首月15元起,快前往官網查看詳情吧


分享文章:雙向循環鏈表詳解及C語言簡單實現-創新互聯
標題路徑:http://www.xueling.net.cn/article/hecce.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 美景之屋3免费 | 亚洲国产精品激情综合图片 | 无码精品A∨在线观看十八禁 | 日韩精品一区二区视频 | gogoWWW人体大胆裸体无遮挡 | 呦交小U女国产精品视频 | 日韩亚射吧 | 亚洲欧美成人a毛片 | 国产成人?合一区二区三区 国产人成一区二区三区影院 | 日韩四区 | 日本99视频| 不卡的在线视频 | 日本高清视频WWW夜色资源 | 国产一区资源 | 中文字幕视频播放 | 秋霞一级鲁丝片免费观看 | 亚洲欧洲在线观看 | 欧美成人A片一区二区不卡 www.丁香.com | 78摸在线观看 | 一区二区三区香蕉视频 | 久久久精品国产99久久精品麻追 | 视频一区视频二区欧美 | 欧美性猛交xxxx乱大交喷浆 | 国产在线第一区 | 亚洲另类久久 | 裸体超大乳抖乳露双乳呻吟 | 欧美日韩精品一区二区三区 | 色婷婷五月色综合AⅤ视频 午夜亚洲国产理论片 | 国产精品亚洲人在线观看 | 国产成人手机在线 | 国产乱子伦一区二区三区视频播放 | 日韩欧美中文字幕视频 | 国产精品亚洲玖玖玖在线观看 | 国产性精品 | 国产中文视频 | 国产精品自在线 | 91三级视频 | 无码av中文字幕免费放 | 亚洲人成色77777在线观看大战P | 蜜月久久99静品久久久久久 | 天天操夜夜操国产精品 |