#include
#include
#define N 5
typedef struct _node_
{
int vertex;
struct _node_ *next;
} linknode, *linklist;
void AddEdge(linklist h, int vertex)
{
linklist p;
while ((h->next != NULL) && (h->next->vertex < vertex)) h = h->next;
p = (linklist)malloc(sizeof(linknode));
p->vertex = vertex;
p->next = h->next;
h->next = p;
return ;
}
int FirstAdj(linknode s[], int u)
{
return s[u].next->vertex;
}
int NextAdj(linknode s[], int u, int v)
{
linklist p;
p = s[u].next;
while (p->vertex != v) p = p->next;
p = p->next;
return (NULL == p ? -1 : p->vertex);
}
int main()
{
int i, j;
linknode s[N] = {{0}};
linklist p;
while (scanf("%d,%d", &i, &j) == 2)
{
AddEdge(s+i, j);
AddEdge(s+j, i);
}
for (i=0; i {
printf("V%d : ", i);
p = s[i].next;
while (p != NULL)
{
printf("V%d ", p->vertex);
p = p->next;
}
printf("\n");
}
return 0;
}
阅读(1077) | 评论(0) | 转发(1) |