• <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 閱讀(3801) 評論(2)  編輯 收藏 引用

            評論

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

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

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

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

            99久久精品国产毛片| 久久综合九色综合欧美狠狠| 国产精品无码久久综合网| 久久久久久亚洲Av无码精品专口 | 成人久久精品一区二区三区| 久久久久久久久久久精品尤物 | 亚洲AV乱码久久精品蜜桃| 亚洲国产成人精品91久久久 | 久久99国产一区二区三区| 99久久精品免费观看国产| 91久久成人免费| 精品无码久久久久久久动漫| 久久99亚洲综合精品首页| 青青热久久国产久精品| 一级女性全黄久久生活片免费| 日日狠狠久久偷偷色综合96蜜桃| 四虎影视久久久免费| 99久久香蕉国产线看观香| 99久久99久久精品国产片果冻| 久久无码高潮喷水| 日本人妻丰满熟妇久久久久久| 久久99亚洲网美利坚合众国| a高清免费毛片久久| 国产亚洲色婷婷久久99精品91| 久久久久噜噜噜亚洲熟女综合| 污污内射久久一区二区欧美日韩| 91麻豆国产精品91久久久| 久久丫精品国产亚洲av| 日本精品久久久中文字幕| 久久久国产精华液| 精品国产日韩久久亚洲| 久久精品国产亚洲77777| 日韩亚洲欧美久久久www综合网| 久久久久噜噜噜亚洲熟女综合| 亚洲伊人久久综合影院| 无码国内精品久久人妻| 日本精品久久久久中文字幕| 久久毛片一区二区| 狠狠色丁香婷婷久久综合不卡 | 激情久久久久久久久久| 欧美精品乱码99久久蜜桃|