• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            付翔的專欄
            在鄙視中成長 記錄成長的點(diǎn)滴
            posts - 106,  comments - 32,  trackbacks - 0

            中間因?yàn)橹羔樀倪\(yùn)用錯(cuò)誤 而導(dǎo)致一系列問題 指針還需要在實(shí)戰(zhàn)中加強(qiáng)理解
            # ifndef dList
            # define dList

            /************************************************************************/
            /* 實(shí)現(xiàn)雙向鏈表 用結(jié)構(gòu)來實(shí)現(xiàn)
                                                                                 
            */


            # define ENDSYMBOL 
            -1 
            //DListNode * head = NULL;
            typedef struct _DListNode
            {
                
            struct _DListNode* pre;
                
            struct _DListNode* next;
                
            int data;
            }DListNode;

            int DListSize;
            /*bool dList_malloc(int n)
            {
                return (malloc(sizeof(DListNode)*n)!=NULL);
            }
            */

            void dlist_init(DListNode *& head)
            {
                
            //DListNode tail;//其他的沒細(xì)看,你的DListNode tail;這里的tail是局部變量應(yīng)該不行,函數(shù)返回后就成了野指針了。
                DListNode *tail = (struct _DListNode*)malloc(sizeof(struct _DListNode));
                
            //*head = (struct _DListNode*)malloc(sizeof(struct _DListNode));
                (head)->next = tail;
                (head)
            ->pre = NULL;
                tail
            ->pre = head;
                tail
            ->next = NULL;
                DListSize 
            = 1;

            }
            void dList_insert(int a,DListNode *& head)
            {
                
            struct _DListNode* node;
                node 
            = (struct _DListNode*)malloc(sizeof(struct _DListNode));
                node 
            ->data = a;
                node 
            ->next = NULL;
                node 
            ->pre = NULL;
                
            if(DListSize == 1)//if(*head == NULL)
                {
                        
            //struct _DListNode* temp;
                    
            //    temp = struct _DListNode*malloc(sizeof(struct _DListNode));
                    
            //    *head = node;
                    
            //    (*head) ->pre = NULL;
                    
            //    (*head) ->next = NULL;
                    (head)->data = a;
                    DListSize 
            ++;
                }
                
            else if(DListSize == 2)
                {
                    (head)
            ->next->data = a;
                    DListSize 
            ++;
                }
                
            else
                {
                    
            struct _DListNode* temp;
                    node 
            = (struct _DListNode*)malloc(sizeof(struct _DListNode));
                    temp 
            = head;
                    
            while(temp->data < a && temp->next!=NULL)
                        temp
            =temp->next;
                    
            /*node->next = temp->next;
                    temp->next->pre = node;
                    node->pre = temp;
                    temp->next = node;
            */
                    node
            ->next = temp->next;
                    
            if((temp)->next )
                        temp
            ->next->pre = node;
                    node
            ->pre = temp;
                    temp
            ->next = node;
                    node
            ->data = a;//之前沒有加這個(gè) 代碼運(yùn)行結(jié)果有誤 但是我之前已經(jīng)賦值了

                    DListSize 
            ++;
                }
            }

            bool dList_delete(int index, DListNode *& head)
            {
                
            if(index <=0 || index > DListSize)
                    
            return false;
                DListNode 
            *temp;
                
            int i ;
                temp 
            = head;
                
            if(index == 1)
                {
                    head
            ->next->pre = NULL;
                    head 
            = head->next;
                    free(temp);
                    temp 
            = NULL;
                }
                
            else 
                {
                    
            for(i = 1; i < index ; i ++)
                        temp 
            = temp->next;
                    temp
            ->next->pre = temp->pre;
                    temp
            ->pre->next = temp->next;
                }
                
            return true;
                
            }
            void dList_print(DListNode *& head)
            {
                DListNode 
            * node = (head);
                
            while(node!=NULL)
                {
                    printf(
            "%d\t",node->data);
                    node 
            = node->next;
                }
            }

            # endif


            posted on 2010-08-03 23:30 付翔 閱讀(231) 評論(0)  編輯 收藏 引用 所屬分類: linux 及 c相關(guān)

            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            CSDN - 我的blog地址

            博客

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久久国产精品无码超碰| 久久伊人五月丁香狠狠色| 2022年国产精品久久久久| 狠狠色丁香久久综合五月| 欧美大战日韩91综合一区婷婷久久青草| 久久久黄片| 久久亚洲精品人成综合网| 99久久精品国产一区二区| 久久免费看黄a级毛片| 97热久久免费频精品99| 亚洲欧美日韩精品久久亚洲区| 人妻无码αv中文字幕久久琪琪布| 91精品国产综合久久婷婷| 亚洲国产成人久久综合一区77| 精品久久久久久成人AV| 久久强奷乱码老熟女网站| 秋霞久久国产精品电影院| 99久久国产综合精品女同图片| 青青草国产精品久久| 一本色道久久综合亚洲精品| 久久国产精品无码网站| 国产午夜久久影院| 久久国产色AV免费观看| 新狼窝色AV性久久久久久| 久久久久无码中| 久久精品二区| 久久99精品久久久久久齐齐| 久久99国产精品久久| 99国产精品久久| 日韩人妻无码精品久久免费一 | 久久91精品久久91综合| 怡红院日本一道日本久久| 久久香蕉国产线看观看精品yw| 少妇无套内谢久久久久| 99久久综合国产精品免费| 性做久久久久久久久老女人| 国产精品gz久久久| 日本高清无卡码一区二区久久| 久久久久国产精品嫩草影院| 日本久久久久久久久久| 国产精品久久久久久久人人看|