Last active
August 29, 2015 14:01
-
-
Save dd1994/82d0654d7a424386e5d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MaxVertices 100 | |
typedef struct{ | |
int vertices[MaxVertices]; | |
int edge[MaxVertices][MaxVertices]; | |
int numV; | |
}adjMatrix; | |
void createGraph(adjMatrix *G, int n) | |
{ | |
int i, j; | |
G->numV = n; | |
printf("input the vertices info:\n"); | |
for (i = 0; i < G->numV; ++i) | |
{ | |
printf("vertices[%d] =\n", i); | |
scanf("%d", &(G->vertices[i])); | |
} | |
printf("input the edge info:\n"); | |
for (i = 0; i < G->numV; ++i) | |
{ | |
for (j = 0; j < G->numV; ++j) | |
{ | |
printf("edge[%d][%d]=:", i, j); | |
scanf("%d", &(G->edge[i][j])); | |
} | |
} | |
} | |
void outputGraph(adjMatrix *G) | |
{ | |
int i, j; | |
printf("printf the vertices info:\n"); | |
for (i = 0; i < G->numV; ++i) | |
{ | |
printf("vertices[%d] = %d\n", i, G->vertices[i]); | |
} | |
printf("printf the edge info:\n"); | |
for (i = 0; i < G->numV; ++i) | |
{ | |
for (j = 0; j < G->numV; ++j) | |
{ | |
printf("edge[%d][%d]=: %d\n", i, j, G->edge[i][j]); | |
} | |
} | |
} | |
int main(void) | |
{ | |
adjMatrix *G; | |
createGraph(G, 6); | |
outputGraph(G); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment