• <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
            一言難盡啊。。。
            最近發現一個怪現象。。。浙大門口斑馬線的紅綠燈是只顯示紅燈的。。。綠燈的時候是全黑的。。。難道是培養耐心?。。?br>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)  編輯 收藏 引用
            哈哈哈哈哈哈
            亚洲av伊人久久综合密臀性色| 久久久久99精品成人片| 亚洲乱码日产精品a级毛片久久| 激情伊人五月天久久综合| 午夜天堂精品久久久久| 久久久久国产精品嫩草影院| 精品久久久久久久久免费影院| 青青草原综合久久大伊人导航| 人妻中文久久久久| 久久精品成人| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 国产成人精品久久一区二区三区av| 久久婷婷五月综合97色一本一本| 热re99久久6国产精品免费| 成人免费网站久久久| 日本三级久久网| 日韩欧美亚洲综合久久影院Ds| 久久这里有精品| 无码国产69精品久久久久网站| 国产精品久久99| 久久亚洲av无码精品浪潮| 囯产精品久久久久久久久蜜桃| 精品久久人妻av中文字幕| 91精品国产91久久久久久| 久久久亚洲精品蜜桃臀| 亚洲国产美女精品久久久久∴| 久久青青草原综合伊人| 亚洲中文字幕伊人久久无码 | 99久久精品这里只有精品| 国产精品欧美久久久久无广告| 久久久久无码精品国产app| 色欲久久久天天天综合网| 婷婷久久综合九色综合98| 久久精品成人| 久久国产精品一区二区| 久久天天婷婷五月俺也去| 久久这里只有精品久久| 精品国产青草久久久久福利| 久久久久久毛片免费看 | 久久ww精品w免费人成| 精品无码人妻久久久久久|