• <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吧  回復  更多評論   

            久久国产福利免费| 模特私拍国产精品久久| 久久精品aⅴ无码中文字字幕不卡| 亚洲精品综合久久| 亚洲中文字幕无码久久精品1| 亚洲午夜久久久久久久久久| 国产精品久久久久久搜索| 久久久久一级精品亚洲国产成人综合AV区 | 久久综合精品国产一区二区三区 | 一本一本久久A久久综合精品| 99久久er这里只有精品18| 欧美一区二区精品久久| 伊人久久成人成综合网222| www性久久久com| 久久久久青草线蕉综合超碰 | 久久精品人人做人人爽电影| 狠狠色噜噜狠狠狠狠狠色综合久久| 久久久无码精品午夜| www久久久天天com| 亚洲国产精品无码久久一线| 久久精品国产一区二区| 国产一区二区三区久久| 亚洲色欲久久久综合网东京热| 久久中文字幕无码专区| 国产成人精品久久| 色综合合久久天天综合绕视看| 久久精品中文闷骚内射| 人妻无码精品久久亚瑟影视 | 少妇久久久久久久久久| 久久久久国产| 国产亚洲色婷婷久久99精品91| 69国产成人综合久久精品| 少妇久久久久久久久久| 色8久久人人97超碰香蕉987| 久久久久免费精品国产| 99久久综合国产精品免费| 亚洲七七久久精品中文国产| 欧美激情精品久久久久久久九九九| 国产午夜精品理论片久久| 久久99精品九九九久久婷婷| 久久综合日本熟妇|