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

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

            /************************************************************************/
            /* 實現雙向鏈表 用結構來實現
                                                                                 
            */


            # 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是局部變量應該不行,函數返回后就成了野指針了。
                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;//之前沒有加這個 代碼運行結果有誤 但是我之前已經賦值了

                    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相關

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

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            CSDN - 我的blog地址

            博客

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久人妻精品一区二区三区| 久久久久久久久久久久久久| 久久久噜噜噜久久中文福利| 久久久国产乱子伦精品作者| 久久香蕉国产线看观看乱码| 国产AⅤ精品一区二区三区久久| 久久久久亚洲AV综合波多野结衣| 亚洲精品99久久久久中文字幕| 国内精品综合久久久40p| 人人狠狠综合久久亚洲88| 久久久免费观成人影院| 久久精品人人做人人爽97| 久久se精品一区二区影院| 久久久国产打桩机| 精品无码人妻久久久久久| 囯产极品美女高潮无套久久久| 99久久777色| 一本色道久久99一综合| 狠狠人妻久久久久久综合蜜桃| 狠狠色婷婷久久一区二区| 国产福利电影一区二区三区,免费久久久久久久精 | 99久久免费国产特黄| 亚洲色欲久久久久综合网| 久久香蕉一级毛片| 久久国产精品99久久久久久老狼| 久久人人爽人人爽人人片AV高清| 国产精自产拍久久久久久蜜| 香蕉久久av一区二区三区| 久久99这里只有精品国产| 激情综合色综合久久综合| 麻豆精品久久精品色综合| 久久99精品久久久久久动态图| 国产精品久久久久久久久久影院| 久久精品国产福利国产琪琪| 久久99国产精一区二区三区| 久久亚洲日韩精品一区二区三区| 国产精品久久久久久久人人看| 亚洲国产高清精品线久久 | 国产精品丝袜久久久久久不卡| 2021久久国自产拍精品| 久久综合88熟人妻|