• <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 付翔 閱讀(231) 評論(0)  編輯 收藏 引用 所屬分類: linux 及 c相關

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

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            CSDN - 我的blog地址

            博客

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            99久久无色码中文字幕| 久久超碰97人人做人人爱| 久久精品国产精品亚洲下载| 丁香久久婷婷国产午夜视频| 色播久久人人爽人人爽人人片AV| 亚洲欧美日韩中文久久| 久久久久亚洲av无码专区| 久久综合久久久| 久久狠狠爱亚洲综合影院| 嫩草影院久久国产精品| 偷窥少妇久久久久久久久| 狠狠色婷婷综合天天久久丁香| 色婷婷久久久SWAG精品| 久久婷婷久久一区二区三区| 亚洲精品成人网久久久久久| 久久免费精品视频| 亚洲精品乱码久久久久久久久久久久 | 久久久久国产视频电影| 久久久久亚洲Av无码专| 久久综合狠狠综合久久97色| 99久久精品国产免看国产一区| 2021国产精品午夜久久| 91久久九九无码成人网站| 色综合久久久久无码专区| 欧洲性大片xxxxx久久久| 欧美久久综合性欧美| 久久久女人与动物群交毛片| 久久婷婷五月综合色奶水99啪| 999久久久免费国产精品播放| 精品综合久久久久久888蜜芽| 久久九九兔免费精品6| 久久人人爽人人爽人人片AV麻烦| 久久精品这里只有精99品| 99久久免费只有精品国产| 999久久久免费国产精品播放| 久久精品国产69国产精品亚洲| 久久亚洲精品成人AV| 久久久久亚洲精品天堂| 国产美女久久久| 四虎国产永久免费久久| 狠狠色噜噜狠狠狠狠狠色综合久久|