• <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>
            付翔的專欄
            在鄙視中成長 記錄成長的點滴
            posts - 106,  comments - 32,  trackbacks - 0

            中間因為指針的運用錯誤 而導致一系列問題 指針還需要在實戰(zhàn)中加強理解
            # ifndef dList
            # define dList

            /************************************************************************/
            /* 實現(xiàn)雙向鏈表 用結(jié)構(gòu)來實現(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;//其他的沒細看,你的DListNode tail;這里的tail是局部變量應該不行,函數(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;//之前沒有加這個 代碼運行結(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 付翔 閱讀(227) 評論(0)  編輯 收藏 引用 所屬分類: linux 及 c相關(guān)

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            CSDN - 我的blog地址

            博客

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            2020久久精品亚洲热综合一本| 国产精品对白刺激久久久| 精品免费tv久久久久久久| 久久免费的精品国产V∧| 欧洲成人午夜精品无码区久久| 久久精品国产色蜜蜜麻豆| 日本欧美国产精品第一页久久| 亚洲va久久久久| 久久婷婷成人综合色综合| 国产激情久久久久影院小草 | 亚洲精品成人网久久久久久| 久久人人爽人人爽人人爽| 亚洲国产精品久久66| 久久夜色精品国产欧美乱| 久久久久国产精品麻豆AR影院| 久久久国产99久久国产一| 精品久久人妻av中文字幕| 久久久久综合国产欧美一区二区| 久久久国产亚洲精品| 欧美久久天天综合香蕉伊| 国产成人综合久久综合| 久久久久亚洲av无码专区| 亚洲AV无码久久精品蜜桃| 亚洲中文字幕无码久久综合网 | 亚洲成av人片不卡无码久久 | 国产精品久久午夜夜伦鲁鲁| 精品国产青草久久久久福利| 欧美日韩精品久久久久| 性高朝久久久久久久久久| 2021国内久久精品| 久久久av波多野一区二区| 久久精品国产99国产精品澳门| 国产精品久久成人影院| 亚洲午夜久久影院| 久久e热在这里只有国产中文精品99| 色综合合久久天天综合绕视看| 久久精品国产一区二区三区不卡| 国产成人精品久久综合| 久久久久久夜精品精品免费啦| 国产91色综合久久免费| 狠狠色婷婷久久综合频道日韩|