17070047 / 17070047/CodeStructureCourse

图的应用 苏欣晨

未關閉
#72 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。