• <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地址

            博客

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            一本久久a久久精品综合香蕉| 国内精品久久国产大陆| 久久久久久夜精品精品免费啦| 久久亚洲国产成人影院| 999久久久免费国产精品播放| 国产L精品国产亚洲区久久| 日韩亚洲国产综合久久久| 精品久久久久久久久午夜福利| 久久综合久久鬼色| 欧美与黑人午夜性猛交久久久| 久久亚洲AV成人无码国产| 久久93精品国产91久久综合| 狠狠综合久久综合中文88| 久久综合久久综合亚洲| 97久久国产亚洲精品超碰热| 欧美性猛交xxxx免费看久久久| 中文字幕乱码久久午夜| 国产成人精品久久综合| 伊人色综合久久天天人手人婷 | 久久精品综合网| 精品综合久久久久久888蜜芽| 久久久这里有精品中文字幕| 99久久免费国产精精品| 久久人人添人人爽添人人片牛牛| 激情综合色综合久久综合| 996久久国产精品线观看| 精品久久久久久国产| 亚洲v国产v天堂a无码久久| 色综合久久中文色婷婷| 久久精品国产亚洲AV麻豆网站| 国产精品久久久久蜜芽| 日韩美女18网站久久精品| 国产精品伊人久久伊人电影| 国内精品人妻无码久久久影院| 婷婷伊人久久大香线蕉AV| 久久亚洲AV无码精品色午夜麻豆| 久久精品无码专区免费| 99久久精品国产毛片| 精品久久久久国产免费| 久久中文精品无码中文字幕| 久久国产视频99电影|