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

            The Fourth Dimension Space

            枯葉北風寒,忽然年以殘,念往昔,語默心酸。二十光陰無一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢令

            數據結構作業之-拓撲排序(C++實現)

            //張宏數據結構作業之__拓撲排序
            //Get Guidance by Mr ZhangHong
            //Student:abilitytao

            #include
            <iostream>
            #include
            <cmath>
            #include
            <cstdio>
            #include
            <algorithm>
            #include
            <stack>
            using namespace std;
            #define MAX 9999

            stack
            <int>mystack;
            int indegree[MAX];

            struct node 
            {
                
            int adjvex;
                node
            * next;
            }
            adj[MAX];

            int Create(node adj[],int n,int m)//鄰接表建表函數,n代表定點數,m代表邊數
            {
                
            int i;
                node 
            *p;
                
            for(i=1;i<=n;i++)
                
            {
                    
                    adj[i].adjvex
            =i;
                    adj[i].next
            =NULL;
                }

                
            for(i=1;i<=m;i++)
                
            {
                    cout
            <<"請輸入第"<<i<<"條邊:";
                    
            int u,v;
                    cin
            >>u>>v;
                    p
            =new node;
                    p
            ->adjvex=v;
                    p
            ->next=adj[u].next;
                    adj[u].next
            =p;
                }

                
            return 1;
            }



            void print(int n)//鄰接表打印函數
            {
                
            int i;
                node 
            *p;
                
            for(i=1;i<=n;i++)
                
            {
                    p
            =&adj[i];
                    
            while(p!=NULL)
                    
            {
                        cout
            <<p->adjvex<<' ';
                        p
            =p->next;
                    }

                    cout
            <<endl;
                }

            }


            void topsort(node adj[],int n)
            {

                
            int i;
                node 
            *p;
                memset(indegree,
            0,sizeof(indegree));
                
            for(i=1;i<=n;i++)
                
            {

                    p
            =adj[i].next;
                    
            while(p!=NULL)
                    
            {
                        indegree[p
            ->adjvex]++;
                        p
            =p->next;
                    }

                }

                
            for(i=1;i<=n;i++)
                
            {

                    
            if(indegree[i]==0)
                        mystack.push(i);
                }

                
            int count=0;
                
            while(mystack.size()!=0)
                
            {

                    i
            =mystack.top();
                    mystack.pop();
                    cout
            <<i<<' ';
                    count
            ++;
                    
            for(p=adj[i].next;p!=NULL;p=p->next)
                    
            {
                        
            int k=p->adjvex;
                        indegree[k]
            --;
                        
            if(indegree[k]==0)
                            mystack.push(k);
                    }

                }

                cout
            <<endl;
                
            if(count<n)cout<<"有回路"<<endl;
            }




            int main()
            {
                
            int n;
                
            int m;
                cout
            <<"請輸入頂點數及邊數:";
                cin
            >>n>>m;
                Create(adj,n,m);
                cout
            <<"輸入的鄰接表為:"<<endl;
                print(n);
                cout
            <<"拓撲排序結果為:"<<endl;
                topsort(adj,n);
                system(
            "pause");
                
            return 0;
            }


            posted on 2009-04-01 17:45 abilitytao 閱讀(3806) 評論(2)  編輯 收藏 引用

            評論

            # re: 數據結構作業之-拓撲排序(C++實現) 2010-07-02 13:18 EIIy

            博主 能不能畫出這個程序的流程圖啊! 急需  回復  更多評論   

            # re: 數據結構作業之-拓撲排序(C++實現)[未登錄] 2010-07-03 10:48 abilitytao

            @EIIy
            聯系我QQ吧  回復  更多評論   

            亚洲а∨天堂久久精品9966| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 久久综合伊人77777| 国产一区二区精品久久岳| 四虎国产精品免费久久久| 久久久青草久久久青草| 国产国产成人精品久久| 亚洲国产成人久久综合野外| 国产精品热久久毛片| 久久精品国产亚洲一区二区| 偷偷做久久久久网站| 亚洲国产精品久久久久网站| 久久精品中文字幕无码绿巨人 | 国产免费久久精品99re丫y| 亚洲伊人久久综合中文成人网| 伊人精品久久久久7777| 久久国产香蕉一区精品| 久久人人爽人人爽人人片AV麻烦 | 丰满少妇人妻久久久久久4| 久久综合给合综合久久| 久久精品国产AV一区二区三区| 天天躁日日躁狠狠久久| 午夜不卡888久久| 午夜精品久久久久| 国产精品99久久免费观看| 精品乱码久久久久久夜夜嗨| 精品久久一区二区| 国产精品成人99久久久久 | 久久久亚洲欧洲日产国码是AV| 久久国产精品-国产精品| 久久久久精品国产亚洲AV无码| 久久这里只有精品视频99| 精品久久人人爽天天玩人人妻| 99久久夜色精品国产网站| 91性高湖久久久久| 久久九九青青国产精品| 97久久精品午夜一区二区| 好久久免费视频高清| 免费观看成人久久网免费观看| 久久精品国产影库免费看 | 久久精品中文騷妇女内射|