17070047 / 17070047/CodeStructureCourse
图的应用 苏欣晨
- Langage dominant
- C++
- Étoiles
- 16
- Forks
- 2
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
```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
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- c
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 30/100