图的深度遍历和广度遍历

#include
using namespace std;
const int maxsize=100;
bool visited[maxsize];
template 
class grahf
{
    public:
        grahf(Datatype a[],int n,int e);
        ~grahf();
        void BFS(int v);
        void DFS(int v);
    private:
        int bianshu,dianshu;
        int bian[maxsize][maxsize];
        Datatype dian[maxsize];
};
template 
grahf ::~grahf()
{
    dianshu=0;
    bianshu=0;
}
template 
grahf ::grahf(Datatype a[],int n,int e)
{
    int i,j,k;
    dianshu=n;
    bianshu=e;
    for(i=0;i>i>>j;
        bian[i][j]=1;
        bian[j][i]=1;
    }
}
template 
void grahf ::DFS(int v)
{
    int y;
    cout<
void grahf ::BFS(int v)
{
    Datatype Q[maxsize];
    int front1=-1,rear=-1;
    cout<>x;
        if(x==1)
        {
            int a[maxsize];
            int o;//点数
            int k;//边数
            cout<<"输入图的点数和边数"<>o>>k;
            cout<<"输入图的点"<>a[i];
            }
            grahf  G(a,o,k);
            cout<<"广度优先遍历为:";
            G.DFS(1);
            cout<>o>>k;
            cout<<"输入图的点"<>a[i];
            }
            grahf  G(a,o,k);
            cout<<"深度优先遍历为:";
            G.BFS(0);
            cout<

你可能感兴趣的:(模板)