数据结构 图的问题
#include<stdio.h>#include<stdlib.h>
#include <malloc.h>
#define False 0
#define True 1
#define Null 0
#define maxsize 20
#define maxvertexnum 20
typedef struct node{
int adjvex;
struct node *next;
}edgenode;
typedef struct {
char vertex;
edgenode *link;
}vexnode,AdjList[maxvertexnum];
typedef struct{
AdjList adjlist;
int n,e;
}Graph;
typedef struct{
int *data;
int *top;
}seqstack;
vexnode g[maxvertexnum];
int visited[maxvertexnum];
void CreatAdjList(Graph &G){
int i,j,k;
edgenode *s;
char c;
printf("please input the set points and the number of edges:\n");
scanf("%d,%d",&G.n,&G.e);
c=getchar();
printf("please input vertex information ( vertex number ):\n");
for(i=1;i<=G.n;i++){
printf("The %d vertices",i);
scanf("%c",&G.adjlist[i].vertex);
c=getchar();
G.adjlist[i].link=NULL;
}
printf("please input the edge information():\n");
for(k=1;k<=G.e;k++){
printf("please enter please input %d edges starting vertex number:\n",k);
scanf("%d",&i);
printf("please enter please input %d edges with a vertex number:\n",k);
scanf("%d",&j);
s=(edgenode*)malloc(sizeof(edgenode));
s->adjvex=j;
s->next=G.adjlist[i].link;
G.adjlist[i].link=s;
}
}
void DisplayAdjList(Graph G)
{
int i;
edgenode *q;
for(i=1;i<=G.n;++i)
{
q=G.adjlist[i].link;
printf("%d",i);
while(q!=NULL)
{
printf("->%d",q->adjvex);
q=q->next;
}
printf("\n");
}
}
void DFSAL(Graph G)
{
edgenode *p;
seqstack s;
int i=1,t;
for(i=1;i<=G.n;i++)
visited[i]=0;
printf("This is a depth-first traversal, traversal order:\n");
s.data=(int*)malloc(maxsize*sizeof(seqstack));
s.top=s.data;
for(i=1;i<=G.n;i++)
{
p=G.adjlist[i].link;
t=i;
if(p==NULL)
{
if(!visited[t])
{
printf("%c",G.adjlist[t].vertex);
visited[t]=True;
}
continue;
}
do{
if(p==NULL)
{
s.top--;
p=G.adjlist[*s.top].link;
if(p!=NULL){
t=p->adjvex;
}
}
else if(!visited[t])
{
printf("%c",G.adjlist[t].vertex);
visited[t]=True;
if(G.adjlist[t].link==NULL)continue;
*s.top=t;
s.top++;
p=G.adjlist[t].link;
if(p==NULL)
{
if(!visited[t])printf("%c",G.adjlist[t].vertex);
}
else t=p->adjvex;
}
else
{
p=p->next;
if(p!=NULL)t=p->adjvex;
}
}while(s.top!=s.data);
}
}
void BFSAL(Graph G){
int v,Q[maxsize];
edgenode * w;
printf("This is the breadth priority traversal, traversal order:\n");
int front=0,rear=0;
for(v=1;v<=G.n;v++)
visited[v]=0;
for(v=1;v<=G.n;v++)
if(!visited[v])
{
visited[v]=1;
printf("%c",G.adjlist[v].vertex);
Q[rear]=v;
rear++;
while (front!=rear)
{
front++;
w=G.adjlist[v].link;
while(w){
if(!visited[w->adjvex])
{
visited[w->adjvex]=1;
printf("%c",G.adjlist[w->adjvex].vertex);
Q[rear]=w->adjvex;
rear++;
}
w=w->next;
}
}
}
}
void main(){
Graph G;
int choice;
char ch;
printf("------create the graph adjacency list storage");
CreatAdjList(G);
printf("have created a map of the adjacent table\n");
DisplayAdjList(G)
while(ch!='n'){
printf("\nPlease select the operating:");
printf("\n1------depth first traversal:");
printf("\n2------breadth priority traversal");
printf("\n3-----sign out\n");
scanf("%d",&choice);
switch(choice){
case 1:DFSAL(G);break;
case 2:BFSAL(G);break;
case 3:ch='n';break;
default:ch='n';
}
}
}
最后实行之后 出现Declaration syntax error 不知道怎么办?