17070047 / 17070047/CodeStructureCourse

图的应用 苏欣晨

Đang mở
#72 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C++
Star
16
Fork
2
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

```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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.