17070047 / 17070047/CodeStructureCourse

图的应用 苏欣晨

Open
#72 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16
Forks
2
PR merge metrics
No merged PRs in 30d

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

Contributor guide

No contributing guide indexed for this repository

Research direction

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.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.