17070047 / 17070047/CodeStructureCourse
图的应用 苏欣晨
- 主要语言
- C++
- 星标
- 16
- 派生
- 2
- PR 合并指标
- 30 天内没有已合并 PR
描述
```c
#include"stdio.h"
#include"stdlib.h"
#define m 20
//标记表
int visited[m];
//边表结点
typedef struct node{
int adjvex;
struct node *next;
}edgenode;#include"stdio.h"
#include"stdlib.h"
#define m 20
//标记表
int visited[m];
//边表结点
//头结点
typedef struct vnode{
char vertex;
edgenode *firstedge;
}vertexnode;
//邻接表类型
typedef struct{
vertexnode adjlist[m];
int n,e;
}adjgraph;
//创建邻接表
adjgraph *creatst()
{
void creat(adjgraph *g);
//int n,e,i;
adjgraph *test;
//vertexnode *kk;
//scanf("%d%d",&n,&e);
test=(adjgraph *)malloc(sizeof(adjgraph));
//test->n=n;
//test->e=e;
/*for(i=0;iadjlist[i]=*kk;
}*/
creat(test);
return test;
}
//创建图
void creat(adjgraph *g)
{
int i,j,k;
edgenode *s;
printf("please input n and e:\n");
scanf("%d%d",&g->n,&g->e);
getchar();
printf("please input %d vertex:\n",g->n);
for(i=0;in;i++)//给头结点的那部分赋值
{
scanf("%c",&g->adjlist[i].vertex);
getchar();
g->adjlist[i].firstedge=NULL;
}
printf("please input %d edges:\n",g->e);
for(k=0;ke;k++)
{
scanf("%d%d",&i,&j);
getchar();
s=(edgenode*)malloc(sizeof(edgenode));
s->adjvex=j;
s->next=g->adjlist[i].firstedge;
g->adjlist[i].firstedge=s;
s=(edgenode*)malloc(sizeof(edgenode));
s->adjvex=i;
s->next=g->adjlist[j].firstedge;
g->adjlist[j].firstedge=s;
}
}
//深度优先遍历
void dfs(adjgraph g,int i)
{
edgenode *p;
printf("visit vertex: %c \n",g.adjlist[i].vertex);
visited[i]=1;
p=g.adjlist[i].firstedge;
while(p)
{
if(!visited[p->adjvex])
dfs(g,p->adjvex);
p=p->next;
}
}
void dfstraverse(adjgraph g)
{
int i;
for(i=0;ifront)
{
j=queue[front++];
p=g.adjlist[j].firstedge;
while(p)
{
if(visited[p->adjvex]==0)
{
printf("%c ",g.adjlist[p->adjvex].vertex);
queue[rear++]=p->adjvex;
visited[p->adjvex]=1;
}
p=p->next;
}
}
}
int bfstraverse(adjgraph g)
{
int i,count=0;
for(i=0;i
贡献指南
这个仓库没有索引到贡献指南
调研方向
The issue body contains a full C program for graph adjacency list creation and traversal, but no description of the problem. First, understand the repository's purpose and existing code structure. Look for test files or expected behavior. The code appears to implement graph operations; check if there are compilation errors, memory leaks, or incorrect traversal outputs. Run the provided code to see if it functions as intended.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 30/100