图的遍历(C++)

#include
#include
#include
#include

const int MaxSize=100;

const int VERTEXNUM=20;
typedef struct{
    int *Qbase;
    int front,rear;
}SqQueue;

void InitQueue(SqQueue &Q){
    Q.Qbase = (int *)malloc(sizeof(int) *VERTEXNUM);

    if(!Q.Qbase)
        return ;

    Q.rear = Q.front = -1;
}

void EnQueue(SqQueue &Q, int i){
    Q.Qbase[Q.rear ++] = i;
}

void DeQueue(SqQueue &Q, int &i){
    i = Q.Qbase[Q.front ++];
}

int QueueEmpty(SqQueue Q){
    if(Q.front == Q.rear)
        return 1;

    return 0;
}

template
class  MGraph
{
public:
    MGraph(T a[],int n,int e);
    ~MGraph(){}
    void DFSTraverse();
    void BFSTraverse(int v);
    void DeepTra(int v[],int n);
private:
    T   vertex[MaxSize];             //节点数组
    int  arc[MaxSize][MaxSize];      //矩阵
    int vertexNum,arcNum;            //节点数与边数
    int visited[MaxSize];            //访问记录
};

template
MGraph::MGraph(T a[],int n,int e)
{
    int i,j;
    vertexNum=n;
    arcNum=e;
    for(i=0;i>i>>j;
        arc[i][j]=1;
        arc[j][i]=1;
    }
}

template
void  MGraph::DFSTraverse()
{
    int i;
    for(i=0;i
void MGraph::DeepTra(int v[],int n)
{
    int i;
    visited[n]=1;
    std::cout<
void MGraph::BFSTraverse(int v)
{
    SqQueue Q;
    Q.front=Q.rear=-1;
    int i;
    for(i=0;i>e;

    std::cout<<"边的个数:"<<"  ";
    std::cin>>n;

    char  s[e];
    for(int i=0;i>s[i];
    }
    MGraph m(s,e,n);
    m.DFSTraverse();
    m.BFSTraverse(0);
    return 0;
}

你可能感兴趣的:(图的遍历(C++))