• <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>
            voip
            風的方向
            厚德致遠,博學敦行!
            posts - 52,comments - 21,trackbacks - 0
            一言難盡啊。。。
            最近發現一個怪現象。。。浙大門口斑馬線的紅綠燈是只顯示紅燈的。。。綠燈的時候是全黑的。。。難道是培養耐心!!!
            Link.cpp文件(這個文件主要用來測試鏈表增刪查改函數):

            #include<stdio.h>
            #include
            "link.h"
            int main()
            {
                
            int i;

                ptonode L[
            100],*L0;

                List l;

                initlist(
            &l);//函數初始化

                
            for(i=10;i>=0;i--)//appendnode函數
                    appendnode(&l,i);

                printlist(
            &l);//printlist函數
                
            /*    sortlist(&l,L);

                for(i=0;i<NodeCount(&l);i++)
                    printf("%d ",L[i]->data);
                printf("\n");
            */


                L0
            =sortlist0(&l);
                
            for(i=0;i<NodeCount(&l);i++)
                    printf(
            "%d ",L0[i]->data);
                printf(
            "\n");
            //    printf("\n");
                
            /*    int Insertnumber,Index;//insertnode函數測試
                while(1)
                {
                    printf("Insertnumber and Index:\n");
                    scanf("%d %d",&Insertnumber,&Index);

                    insertnode(&l,Index,Insertnumber);
                    printlist(&l);
                }

                int deletenumberindex;
                while(1)
                {
                    printf("deletenumberindex:\n");
                    scanf("%d",&deletenumberindex);

                    deletenode(&l,deletenumberindex);
                    printlist(&l);
                }
            */


            /*    int *p;//地址值++是加上指針所指向數據類型大小
                int a[10]={0,1,2,3,4,5,6,7,8,9};
                p=a;
                printf("%d\n",p);
                p++;
                printf("%d\n",p);
                return 0;
            */

                
            return 0;
            }


            Link1.cpp文件(函數定義):
            #include<stdio.h>
            #include
            "link.h"
            #include
            <stdlib.h>
            #include
            <string.h>
            static ptonode locatepos(List *l,int index)//查找節點。。
            {
                ptonode pnode
            =*l;
                
            int i=0;
                
            while(pnode!=NULL)
                
            {
                    i
            ++;
                    
            if(i==index)
                        
            return pnode;
                    pnode
            =pnode->next;
                }

                
            return pnode;
            }



            ptonode findnode(List
            * l,elementtype data)//查找節點
            {
                ptonode pnode
            =*l;
                
            while(pnode!=NULL)
                
            {
                    
            if(pnode->data=data)
                        
            return pnode;
                    pnode
            =pnode->next;
                }

                
            return pnode;
            }


            static ptonode createnode(elementtype data)//構建一個節點
            {
                ptonode pnode;
                pnode
            =(ptonode)malloc(sizeof(Node));
                pnode
            ->data=data;
                pnode
            ->next=NULL;
                
            return pnode;
            }


            ptonode findlast(List
            * l)//查找最后一個節點
            {
                ptonode pnode
            =*l;
                
            if(*l==NULL)
                  
            return *l;
                
            while(pnode->next!=NULL)
                pnode
            =pnode->next;
                 
            return pnode;
            }


            void initlist(List* l)//初始化雖然只有一句代碼,但是指針作為參數傳遞需要掌握。。。而且這里比較很難理解
            {
            //to-do
            *l=NULL;
            }

            void appendnode(List* l,elementtype data)//最后位置插入節點
            {
              
            //to-do
              ptonode pnode,pprev;
              pnode
            =createnode(data);
              pprev
            =findlast(l);
              
            if(pprev==NULL)
                
            *l=pnode;
              
            else
                pprev
            ->next=pnode;   
            }


            int NodeCount(List *l)//節點計數
            {
                ptonode pnode
            =*l;
                
            int count=0;
                
            while(pnode!=NULL)
                
            {
                    count
            ++;
                    pnode
            =pnode->next;
                }

                
            return count;
            }


            void insertnode(List* l,int index,elementtype data)//在第index后面插入一個節點
            {
            //    int i;
                int count;
                count
            =NodeCount(l);
                
            if(index<0||index>count)
                
            {
                    printf(
            "Wrong insert position!index should in 0-%d\n",count);
                    
            return;
                }

                ptonode pnode
            =NULL,pprev=*l,pprevnext=NULL;
            //    pnode=(ptonode)malloc(sizeof(Node));
                pnode=createnode(data);

                
            if(index==0)
                
            {
                    pnode
            ->next=*l;
                    
            *l=pnode;
                    
            return;
                }


                pprev
            =locatepos(l,index);
                pnode
            ->next=pprev->next;
                pprev
            ->next=pnode;
                
            /*
                for(i=1;i<index;i++)
                  pprev=pprev->next;
                //pprev->next=ptonode;
                pprevnext=pprev->next;
                pprev->next=pnode;
                pnode->next=pprevnext;
            */

            }


            void deletenode(List* l,int index)//刪除第index個節點
            {
                
            int count;
                count
            =NodeCount(l);
                
            if(*l==NULL||index<=0||index>count)
                
            {
                    printf(
            "Wrong insert position!index should in 0-%d\n",count);
                    
            return ;
                }


                ptonode pprev
            =*l,pnode=NULL,fnode;

                
            if(index==1)
                
            {
                    
            *l=pprev->next;
                    free(pprev);
                    
            return;
                }

                
            int i;
                
            for(i=1;i<index-1;i++)
                    pprev
            =pprev->next;
                
                fnode
            =pprev->next;
                pnode
            =fnode->next;
                free(fnode);
                pprev
            ->next=pnode;
                
            return;
            }




            void editnode(List* l,int index,elementtype data)
            {
                ptonode pnode;
                pnode
            =locatepos(l,index);
                pnode
            ->data=data;
            }



            void sortlist(List *l,ptonode L[])//從小到大排序。。數組方式實現排序。。。局限性很大
            {
                
            int count;
                
            int i,j;
                count
            =NodeCount(l);
                ptonode  head;
                
                head
            =*l;

                
            for(i=0;i<count;i++)
                
            {
                    L[i]
            =head;
                    head
            =head->next;
                }


                
                 ptonode  temp; 
            //交換排序。。
                 for(i=0;i<count-1;i++)
                 
            {
                    temp
            =L[i];
                    
            for(j=i+1;j<count;j++)
                    
            {
                        
            if(L[i]->data>L[j]->data)
                        
            {
                            temp
            =L[i];
                            L[i]
            =L[j];
                            L[j]
            =temp;
                        }

                    }

                 }

            /*    L=(ptonode)malloc(count*sizeof(ptonode));

                for(i=0,pnode=L;i<count;i++,pnode++)//地址值++是加上指針所指向數據類型大小
                {
                    pnode=head;
                    head=head->next;
                }
                
                 ptonode  temp; //交換排序。。
                 for(i=0;i<count-1;i++)
                 {
                    temp=&L[i];
                    for(j=i+1;j<count;j++)
                    {
                        if(L[i].data>L[j].data)
                        {
                            temp=&L[i];
                            &L[i]=&L[j];
                            &L[j]=temp;
                        }
                    }
                 }
            */

            //     return L;
            }



            ptonode  
            *sortlist0(List *l)//動態開辟內存實現數組排序。。。開心了。。。
            {
                
            int i,j,count;
                ptonode 
            *L,*pnode,head;
                head
            =*l;
                count
            =NodeCount(l);
                L
            =(ptonode *)malloc(count*sizeof(ptonode));//這里是一個指針的指針。。。這。。

                
            for(i=0,pnode=L;i<count;i++,pnode++)//地址值++是加上指針所指向數據類型大小
                {
                    
            *pnode=head;
                    head
            =head->next;
                }

                
                 ptonode  temp; 
            //交換排序。。
                 for(i=0;i<count-1;i++)
                 
            {
                    temp
            =L[i];
                    
            for(j=i+1;j<count;j++)
                    
            {
                        
            if(L[i]->data>L[j]->data)
                        
            {
                            temp
            =L[i];
                            L[i]
            =L[j];
                            L[j]
            =temp;
                        }

                    }

                 }

                
            return L;
            }

            void emptylist(List *l)//清空
            {
                ptonode pnode
            =*l,fnode;
                
            if(!pnode)
                    
            return;
                
            else
                    
            while(pnode!=NULL)
                    
            {
                        fnode
            =pnode;
                        pnode
            =pnode->next;
                        free(fnode);
                    }

                
            return ;
            }


            void printlist(List *l)//打印
            {
              ptonode pnode
            =*l;
              
            while(pnode!=NULL)
              
            {
                printf(
            "%d ",pnode->data);
                pnode
            =pnode->next;
              }

              printf(
            "\n");
            }




            Link.h頭文件(這個文件主要用來定義數據結構,以及函數申明):
            //#ifndef LIST_H
            //#define LIST_H
            typedef int elementtype;

            struct Node
            {
                elementtype  data;
                
            struct Node *next;
            }
            ;

            typedef 
            struct Node Node;
            typedef Node
            * ptonode;
            typedef Node
            * List;


            void initlist(List* l);
            void appendnode(List* l,elementtype data);
            void insertnode(List* l,int index,elementtype data);
            void deletenode(List* l,int index);
            void editnode(List* l,int index,elementtype data);
            ptonode findnode(List
            * l,elementtype data);
            void sortlist(List* l,ptonode L[]);
            ptonode 
            *sortlist0(List* l);
            void emptylist(List *l);
            void printlist(List *l);
            int NodeCount(List *l);
            posted on 2010-10-31 20:05 jince 閱讀(254) 評論(0)  編輯 收藏 引用
            哈哈哈哈哈哈
            久久精品中文字幕有码| 少妇久久久久久久久久| 99热成人精品热久久669| 久久综合鬼色88久久精品综合自在自线噜噜 | 日产精品久久久久久久| 青青青青久久精品国产h| 亚洲国产精品无码成人片久久| 四虎久久影院| 人妻系列无码专区久久五月天| 少妇被又大又粗又爽毛片久久黑人| 久久久中文字幕| 久久99精品国产99久久6男男| 国产精品久久久久影院嫩草| 人妻无码αv中文字幕久久琪琪布| 久久精品国产亚洲精品2020| 日韩精品久久无码人妻中文字幕 | 久久精品人妻中文系列| 欧美精品一区二区久久| 久久强奷乱码老熟女网站| 国产成人精品综合久久久久 | 人人狠狠综合久久亚洲| 久久99精品久久久久久噜噜| 久久久久久久91精品免费观看| 99久久国产综合精品女同图片| 欧美噜噜久久久XXX| 国产精品久久久久aaaa| 久久综合色之久久综合| 99久久99久久精品国产片果冻| 国产美女久久久| 久久人人爽人人精品视频| 亚洲va久久久噜噜噜久久| 国产精品成人久久久久久久| 免费无码国产欧美久久18| 青青青伊人色综合久久| 中文字幕日本人妻久久久免费| 国产免费久久精品99久久| 精品国产乱码久久久久久呢| 亚洲欧美日韩精品久久| 亚洲成色www久久网站夜月| 久久本道久久综合伊人| 99久久久国产精品免费无卡顿|