老熟女激烈的高潮_日韩一级黄色录像_亚洲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
主站蜘蛛池模板: 欧美日韩一区二区三区自拍 | 91精品免费在线 | videoshd欧美贵妇hd | 在线超碰| 亚洲精品无人一区二区 | 亚洲天堂网络 | 色老头91 | 国新精品乱码一区二区三区18 | 91影视在线免费观看 | 被夫上司強暴人妻中文字幕 | 小sao货水好多真紧h无码视频 | 日韩av中文字幕一区二区 | 亚洲国产精品无码中文字2022 | 五月丁香六月综合缴清无码 | 91超碰九色| 亚洲a视| 久久人妻AV中文字幕 | a级毛片免费高清在线播放 国产性猛交╳XXX乱大交 | 嫩草影院入口ncyy | av成人福利 | 午夜高清国产拍精品 | 精品国产乱码久久久久久老虎 | 妖精森林的救世主动漫在线观看 | 日本视频一二三区中文字幕 | 亚洲综合自拍网 | 18av在线免费观看 | 图片区小说区欧洲区 | 内射在线Chinese | 一级毛片全部免费播放特黄 | 日韩精品无码免费专区午夜不卡 | 欧洲成在人线视频免费 | 91www在线观看 | 海浪在线观看免费版 | 久热精品在线播放 | 曰韩无码二三区中文字幕 | 久草在线最新免费 | 国产午夜福利在线机视频 | 天天天欲色欲色WWW免费 | 欧美性猛交ⅹxxx乱大交3 | 成全视频大全免费观看 | 麻豆影音先锋 |