#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define MAX_VERTICES 50
int visited[MAX_VERTICES];
typedef struct GraphNode {
int vertex;
struct GraphNode *link;
} GraphNode;
typedef struct GraphType {
int n;
GraphNode *adj_list[MAX_VERTICES];
} GraphType;
void graph_init(GraphType *g) {
int v;
g->n = 0;
for(v=0; v<MAX_VERTICES; v++)
g->adj_list[v] = NULL;
}
void insert_vertex(GraphType *g, int v){
if( ((g->n)+1 > MAX_VERTICES )){
fprintf(stderr,"그래프 정점의 개수초과");
}
g->n++;
}
void insert_edge(GraphType *g, int u, int v){
GraphNode *node;
if( u>= g->n || v>= g->n){
fprintf(stderr, "그래프 :정점번호 오류");
return;
}
node = (GraphNode *)malloc(sizeof(GraphNode));
node->vertex = v;
node->link = g->adj_list[u];
g->adj_list[u] = node;
}
'이전것 > 개발' 카테고리의 다른 글
Dijkstra's algorithm (0) | 2014.11.11 |
---|---|
kruskal Greedy Method (0) | 2014.11.06 |
너비 우선 탐색 (0) | 2014.11.06 |
TOTAL SORT F1 (0) | 2014.10.10 |
Total_Sort (0) | 2014.10.08 |