#include
#include
#define MAXSIZE 10
int G[MAXSIZE][MAXSIZE],Nv,Ne,visit[MAXSIZE]={0},getnext[MAXSIZE]={0},visit_2[MAXSIZE]={0},getnext_2[MAXSIZE]={0};
struct TreeQueue{
int Data;
struct TreeQueue Next;
};
typedef struct {
struct TreeQueue *Front;
struct TreeQueue *Rear;
}Queue;
typedef Queue *Link;
Link CreateQueue()
{
Link Q;
struct TreeQueue *Node=(TreeQueue)malloc(sizeof(struct TreeQueue));
Node->Next=NULL;
Q->Front=Q->Rear=Node;
return Q;
}
void AddQ(int data,Link Q)
{
struct TreeQueue Node=(TreeQueue)malloc(sizeof(struct TreeQueue));
Node->Data=data;
Node->Next=NULL;
Q->Rear->Next=Node;
Q->Rear=Q->Rear->Next;
}
int DeleteQ(Link Q)
{
TreeQueue* temp;
int ele;
temp=Q->Front->Next;
Q->Front->Next=temp->Next;
ele=temp->Data;
free(temp);
return ele;
}
void BuildGraph()
{
int i,j,v1,v2;
scanf("%d",&Nv);
for(i=0;i
{
for(j=0;j
{
G[i][j]=0;
}
}
scanf("%d",&Ne);
for(i=0;i
{
scanf("%d %d",&v1,&v2);
G[v1][v2]=1;
G[v2][v1]=1;
}
}
void DFS(int v)
{
int i;
visit[v]++;
if(visit[v]==1)
{
printf("%d ",v);
getnext[v]=1;
}
for(i=0;i
{
if(G[v][i]==1)
{
if(visit[i]==0)
{
DFS(i);
}
}
}
}
void BFS(int v)
{
Queue *Q=CreateQueue();
visit_2[v]++;
if(visit_2[v]==1)
{
printf("%d ",v);
getnext_2[v]=1;
}
AddQ(v,Q);
while(Q->Rear!=Q->Front)
{
int i;
v=DeleteQ(Q);
for(i=0;i<MAXSIZE;i++)
{
if(G[v][i]==1)
{
if(visit_2[i]==0)
{
visit_2[v]++;
if(visit_2[v]==1)
{
printf("%d ",v);
getnext_2[v]=1;
}
AddQ(i,Q);
}
}
}
}
}
int main()
{
int i;
BuildGraph();
for(i=0;i<Nv;i++)
{
if(getnext[i]==0)
{
printf("{ ");
DFS(i);
printf("}\n");
}
}
for(i=0;i<Nv;i++)
{
if(getnext_2[i]==0)
{
printf("{ ");
BFS(i);
printf("}\n");
}
}
return 0;
}
这是代码 为啥我的编译器疯狂报错TreeQueue没定义??
.c||In function 'CreateQueue':|
.c|17|error: 'TreeQueue' undeclared (first use in this function)|
.c|17|error: (Each undeclared identifier is reported only once|
.c|17|error: for each function it appears in.)|
.c|17|error: expected expression before ')' token|
.c||In function 'AddQ':|
.c|25|error: 'TreeQueue' undeclared (first use in this function)|
.c|25|error: expected expression before ')' token|
.c||In function 'DeleteQ':|
.c|33|error: 'TreeQueue' undeclared (first use in this function)|
.c|33|error: 'temp' undeclared (first use in this function)|
||=== Build finished: 8 errors, 0 warnings ===|