Skip to content

Instantly share code, notes, and snippets.

@dd1994
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dd1994/82d0654d7a424386e5d7 to your computer and use it in GitHub Desktop.
Save dd1994/82d0654d7a424386e5d7 to your computer and use it in GitHub Desktop.
#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