欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

C語(yǔ)言數(shù)據(jù)結(jié)構(gòu)雙向鏈表以及基本功能實(shí)現(xiàn)

項(xiàng)目頭文件:

成都創(chuàng)新互聯(lián)公司是專(zhuān)業(yè)的靈臺(tái)網(wǎng)站建設(shè)公司,靈臺(tái)接單;提供成都網(wǎng)站建設(shè)、成都網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行靈臺(tái)網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!

#ifndef _LIST_H_
#define _LIST_H_
#include <stdio.h>
#include<stdlib.h>

typedef int LTDataType;
typedef struct ListNode {
    LTDataType _data;
    struct ListNode* _next;
    struct ListNode* _prev;
}ListNode;

typedef struct List {
    ListNode* _head;
}List;

void ListInit(List* plist);//初始化
void ListDestory(List* plist);//清空鏈表

void ListPushBack(List* plist, LTDataType x);//后插
void ListPopBack(List* plist);//后刪
void ListPushFront(List* plist, LTDataType x);
void ListPopFront(List* plist);

ListNode* ListFind(List* plist, LTDataType x);//查找

void ListMerge(List* pList1, List* pList2);//將有序鏈表有序合并

void ListInsertFront(ListNode* pos, LTDataType x);
void ListInsertAfter(ListNode* pos, LTDataType x);
// ????pos??????????
void ListErase(ListNode* pos);//刪除
void ListRemove(List* plist, LTDataType x);//移除指定
void ListRemoveAll(List* plist, LTDataType x);//移除指定的全部
void ListPrint(List* plist);//打印

#endif /*_LIST_H_*/

具體功能實(shí)現(xiàn):

void ListInit(List* plist)
{
    plist->_head = (ListNode*)malloc(sizeof(ListNode));
    plist->_head->_next = plist->_head;
    plist->_head->_prev = plist->_head;
}
void ListDestory(List* plist)
{
    while (plist->_head->_next != plist->_head)
    {
        ListPopFront(plist);
    }
    free(plist->_head);
    plist->_head = NULL;
}

void ListPushBack(List* plist, LTDataType x)
{
    ListInsertFront(plist->_head, x);
}
void ListPopBack(List* plist)
{
    ListErase(plist->_head->_prev);
}
void ListPushFront(List* plist, LTDataType x)
{
    ListInsertAfter(plist->_head, x);
}
void ListPopFront(List* plist)
{
    ListErase(plist->_head->_next);
}

ListNode* ListFind(List* plist, LTDataType x)
{
    ListNode* cur;
    for (cur = plist->_head->_next; cur != plist->_head; cur = cur->_next)
    {
        if (cur->_data == x)
        {
            return cur;
        }
    }
    return NULL;
}

void ListMerge(List* pList1, List* pList2)//將兩個(gè)有序鏈表合并為一個(gè)新的有序鏈表并返回。新鏈表是通過(guò)拼接給定的兩個(gè)鏈表的所有節(jié)點(diǎn)組成的
{
    ListNode* cur1=pList1->_head->_next, *cur2=pList2->_head->_next;
    ListNode* tmp1, *tmp2;
    while (cur1 != pList1->_head&&cur2 != pList2->_head)
    {
        if (cur1->_data > cur2->_data)
        {
            tmp1 = cur1->_prev;
            tmp2 = cur2->_next;

            tmp1->_next = cur2;
            cur2->_next = cur1;
            cur1->_prev = cur2;
            cur2->_prev = tmp1;
            cur2 = tmp2;
        }
        else
        {
            cur1 = cur1->_next;
        }
    }

    if (cur1 == pList1->_head)
    {
        tmp2 = pList2->_head->_prev;
        cur2->_prev = cur1->_prev;
        cur1->_prev->_next = cur2;
        tmp2->_next = cur1;
        cur1->_prev = tmp2;
    }
    free(pList2->_head);
    pList2->_head = NULL;
}

void ListInsertFront(ListNode* pos, LTDataType x)
{
    ListNode* cur = (ListNode*)malloc(sizeof(ListNode));
    cur->_data = x;
    cur->_next = pos;
    cur->_prev = pos->_prev;
    pos->_prev->_next = cur;
    pos->_prev = cur;
}
void ListInsertAfter(ListNode* pos, LTDataType x)
{
    ListNode* cur = (ListNode*)malloc(sizeof(ListNode));
    cur->_data = x;
    cur->_prev = pos;
    cur->_next = pos->_next;
    pos->_next->_prev = cur;
    pos->_next = cur;
}
// ????pos??????????
void ListErase(ListNode* pos)
{
    pos->_prev->_next = pos->_next;
    pos->_next->_prev = pos->_prev;
    free(pos);
}
void ListRemove(List* plist, LTDataType x)
{
    ListNode * cur = ListFind(plist, x);

    if (cur)
    {
        ListErase(cur);
    }
}
void ListRemoveAll(List* plist, LTDataType x)
{
    ListNode* cur;
    for (cur = plist->_head->_next; cur != plist->_head; cur = cur->_next)
    {
        if (cur->_data == x)
        {
            ListErase(cur);
        }
    }
}

void ListPrint(List* plist)
{
    ListNode* cur;
    if (plist->_head == NULL)
    {
        printf("NULL\n");
        return;
    }
    printf("head->");
    for (cur = plist->_head->_next; cur != plist->_head; cur = cur->_next)
    {
        printf("%d-> ",cur->_data);
    }
    printf("head\n");
}

本文名稱:C語(yǔ)言數(shù)據(jù)結(jié)構(gòu)雙向鏈表以及基本功能實(shí)現(xiàn)
分享地址:http://chinadenli.net/article24/pgpoce.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)動(dòng)態(tài)網(wǎng)站移動(dòng)網(wǎng)站建設(shè)網(wǎng)站內(nèi)鏈域名注冊(cè)用戶體驗(yàn)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)