# 数据结构图的问题

tondayong1981 软件工程师  2004-05-08 02:41:23
#include"stdio.h"
#define n 4
#define e 6
typedef struct node
struct node *next;
}edgenode;
typedef struct
{int vertex;
}vexnode;
typedef struct qnode
{int data;
struct qnode *next;

typedef struct

vexnode ga[n];
int visited[n];

{int i,j,k;
edgenode *s;
for(i=0;i<n;i++)
{scanf("%d",&ga[i].vertex);
}
for(k=0;k<e;k++)
{scanf("%d%d",&i,&j);
s=(edgenode *)malloc(sizeof(edgenode));
s=(edgenode *)malloc(sizeof(edgenode));
}
}

DFSL(int i)
{int j;
edgenode *p;
printf("%5d",ga[i].vertex);
visited[i]=1;
while(p!=NULL)
p=p->next;
}
}

q->front->next=NULL;
q->rear=q->front;
}

{if(q->front==q->rear)
return 1;
else return 0;
}

q->rear=q->rear->next;
q->rear->data=x;
q->rear->next=NULL;
}
int v;
if(q->front==q->rear)
{printf("queue is empty");v=0;}
else{p=q->front->next;
q->front->next=p->next;
if(p->next==NULL)
q->rear=q->front;
v=p->data;
free(p);}
return v;
}

BFSL(int k)
{int i;
edgenode *p;
q=&queue;
printf("%5d",ga[k].vertex);
visited[k]=1;
ENQUEUE(q,k);
while(!EMPTY(q))
{ i=DEQUEUE(q);
while(p!=NULL)

}
p=p->next;}
}
}

main()
{int i,j,v,u;
edgenode *p;
for(i=0;i<n;i++)
{printf("<%d> %d",i,ga[i].vertex);
while(p!=NULL)
p=p->next;
}
printf("->NULL");
printf("\n");
}
printf("1.DFSL:\n");
printf("2.BFSL\n");
printf("3.exit:\n");
scanf("%d",&j);
while(j!=3)
{switch(j)
printf("\n");break;
case 2:printf("please input another start point:\n");scanf("%d",&u);BFSL(u);
printf("\n");break;}
scanf("%d",&j);
}
}

...全文
92 6 点赞 打赏 收藏 举报

6 条回复

tondayong1981 2004-06-30

• 打赏
• 举报

tondayong1981 2004-06-14

• 打赏
• 举报

xiaohai84 2004-06-09
void DFS(ALGraph G,int v) {
ArcNode *p;
visited[v]=1;
pf("%c",G.vertices[v].data);
for(p=G.vertices[v].firstarc;p!=NULL;p=p->nextarc)
}

void DFStravels(ALGraph G) { //深度优先遍历
for(int i=0;i<G.vexnum;i++) visited[i]=0;
for(i=0;i<G.vexnum;i++)
if(!visited[i]) DFS(G,i);
}

void BFStravels(ALGraph G) { //广度优先遍历
SqQueue Q;
ArcNode *p;
int u,w;
for(int v=0;v<G.vexnum;v++) visited[v]=0;
InitQueue(Q);//置空的辅助队列Q
for(v=0;v<G.vexnum;v++)
if(!visited[v]) {
visited[v]=1;
pf("%c",G.vertices[v].data);
EnQueue(Q,v);
while(Q.front!=Q.rear) {
DeQueue(Q,u);
for(p=G.vertices[u].firstarc;p!=NULL;p=p->nextarc) {
if(!visited[w]) {
visited[w]=1;
pf("%c",G.vertices[w].data);
EnQueue(Q,w);
}//if
}//for
}//while
}//if
}//
• 打赏
• 举报

bestme 2004-05-12

• 打赏
• 举报

tondayong1981 2004-05-11

• 打赏
• 举报

klbt 2004-05-09

• 打赏
• 举报

230

2004-05-08 02:41