Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. struct graphrec{
  2.   struct vertex *vertices;
  3.   int num_vert;
  4.   int **edges;
  5. };
  6.  
  7.  
  8. graph graph_new(int num_vertices){
  9.   graph g = malloc(sizeof *g);
  10.   g->num_vert = num_vertices;
  11.   const size_t row_pointers_bytes = num_vertices * sizeof *g->edges;
  12.   const size_t row_elements_bytes = num_vertices * sizeof **g->edges;
  13.   g->edges = malloc(row_pointers_bytes + num_vertices * row_elements_bytes);
  14.   g->vertices = malloc(num_vertices * sizeof(g->vertices));
  15.   return g;
  16. }
  17.  
  18. void graph_free(graph g){
  19.   free(g->vertices);
  20.   free(g->edges);
  21.   free(g);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement