C programming fill in the following code #include "graph.h" #include #include /* initialise an empty graph */ /* return pointer to initialised graph */ Graph *init_graph(void) { } /* release memory for graph */ void free_graph(Graph *graph) { } /* initialise a vertex */ /* return pointer to initialised vertex */ Vertex *init_vertex(int id) { } /* release memory for initialised vertex */ void free_vertex(Vertex *vertex) { } /* initialise an edge. */ /* return pointer to initialised edge. */ Edge *init_edge(void) { } /* release memory for initialised edge. */ void free_edge(Edge *edge) { } /* remove all edges from vertex with id from to vertex with id to from graph. */ void remove_edge(Graph *graph, int from, int to) { } /* remove all edges from vertex with specified id. */ void remove_edges(Graph *graph, int id) { } /* output all vertices and edges in graph. */ /* each vertex in the graphs should be printed on a new line */ /* each vertex should be printed in the following format: */ /* vertex_id: edge_to_vertex[weight] edge_to_vertex[weight] ... */ /* for example: */ /* 1: 3[1.00] 5[2.00] */ /* indicating that vertex id 1 has edges to vertices 3 and 5 */ /* with weights 1.00 and 2.00 respectively */ /* weights should be output to two decimal places */ void print_graph(Graph *graph) { } /* find vertex with specified id in graph. */ /* return pointer to vertex, or NULL if no vertex found. */ Vertex *find_vertex(Graph *graph, int id) { } /* create and add vertex with specified id to graph. */ /* return pointer to vertex or NULL if an error occurs. */ /* if vertex with id already exists, return pointer to existing vertex. */ Vertex *add_vertex(Graph *graph, int id) { } /* remove vertex with specified id from graph. */ /* remove all edges between specified vertex and any other vertices in graph. */ void remove_vertex(Graph *graph, int id) { } /* add directed edge with specified weight between vertex with id from */ /* to vertex with id to. */ /* if no vertices with specified ids (from or to) exist */ /* then the vertices will be created. */ /* multiple edges between the same pair of vertices are allowed. */ /* return pointer to edge, or NULL if an error occurs found. */ Edge *add_edge(Graph *graph, int from, int to, double weight) { } /* add two edges to graph, one from vertex with id from to vertex with id to, */ /* and one from vertex with id to to vertex with id from. */ /* both edges should have the same weight */ /* if no vertices with specified ids (from or to) exist */ /* then the vertices will be created. */ /* multiple vertices between the same pair of vertices are allowed. */ void add_edge_undirected(Graph *graph, int from, int to, double weight) { } /* return array of node ids in graph. */ /* array of node ids should be dynamically allocated */ /* set count to be the number of nodes in graph */ /* return NULL if no vertices in graph */ int *get_vertices(Graph *graph, int *count) { } /* return array of pointers to edges for a given vertex. */ /* array of edges should be dynamically allocated */ /* set count to be number of edges of vertex */ /* return NULL if no edges from/to vertex */ Edge **get_edges(Graph *graph, Vertex *vertex, int *count) { } /* return pointer to edge from vertex with id from, to vertex with id to. */ /* return NULL if no edge */ Edge *get_edge(Graph *graph, int from, int to) { } /* return id of destination node of edge. */ int edge_destination(Edge *edge) { } /* return weight of edge. */ double edge_weight(Edge *edge) { }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C programming

fill in the following code 

#include "graph.h"

#include <stdio.h>
#include <stdlib.h>

/* initialise an empty graph */
/* return pointer to initialised graph */
Graph *init_graph(void)
{
}

/* release memory for graph */
void free_graph(Graph *graph)
{
}

/* initialise a vertex */
/* return pointer to initialised vertex */
Vertex *init_vertex(int id)
{
}

/* release memory for initialised vertex */
void free_vertex(Vertex *vertex)
{
}

/* initialise an edge. */
/* return pointer to initialised edge. */
Edge *init_edge(void)
{
}

/* release memory for initialised edge. */
void free_edge(Edge *edge)
{
}

/* remove all edges from vertex with id from to vertex with id to from graph. */
void remove_edge(Graph *graph, int from, int to)
{
}

/* remove all edges from vertex with specified id. */
void remove_edges(Graph *graph, int id)
{
}

/* output all vertices and edges in graph. */
/* each vertex in the graphs should be printed on a new line */
/* each vertex should be printed in the following format: */
/* vertex_id: edge_to_vertex[weight] edge_to_vertex[weight] ... */
/* for example: */
/* 1: 3[1.00] 5[2.00] */
/* indicating that vertex id 1 has edges to vertices 3 and 5 */
/* with weights 1.00 and 2.00 respectively */
/* weights should be output to two decimal places */
void print_graph(Graph *graph)
{
}

/* find vertex with specified id in graph. */
/* return pointer to vertex, or NULL if no vertex found. */
Vertex *find_vertex(Graph *graph, int id)
{
}

/* create and add vertex with specified id to graph. */
/* return pointer to vertex or NULL if an error occurs. */
/* if vertex with id already exists, return pointer to existing vertex. */
Vertex *add_vertex(Graph *graph, int id)
{
}

/* remove vertex with specified id from graph. */
/* remove all edges between specified vertex and any other vertices in graph. */
void remove_vertex(Graph *graph, int id)
{
}

/* add directed edge with specified weight between vertex with id from */
/* to vertex with id to. */
/* if no vertices with specified ids (from or to) exist */
/* then the vertices will be created. */
/* multiple edges between the same pair of vertices are allowed. */
/* return pointer to edge, or NULL if an error occurs found. */
Edge *add_edge(Graph *graph, int from, int to, double weight)
{
}

/* add two edges to graph, one from vertex with id from to vertex with id to, */
/* and one from vertex with id to to vertex with id from. */
/* both edges should have the same weight */
/* if no vertices with specified ids (from or to) exist */
/* then the vertices will be created. */
/* multiple vertices between the same pair of vertices are allowed. */
void add_edge_undirected(Graph *graph, int from, int to, double weight)
{
}

/* return array of node ids in graph. */
/* array of node ids should be dynamically allocated */
/* set count to be the number of nodes in graph */
/* return NULL if no vertices in graph */
int *get_vertices(Graph *graph, int *count)
{
}

/* return array of pointers to edges for a given vertex. */
/* array of edges should be dynamically allocated */
/* set count to be number of edges of vertex */
/* return NULL if no edges from/to vertex */
Edge **get_edges(Graph *graph, Vertex *vertex, int *count)
{
}

/* return pointer to edge from vertex with id from, to vertex with id to. */
/* return NULL if no edge */
Edge *get_edge(Graph *graph, int from, int to)
{
}

/* return id of destination node of edge. */
int edge_destination(Edge *edge)
{
}

/* return weight of edge. */
double edge_weight(Edge *edge)
{
}

 

 

h graph.h 1.16 KB
1 #ifndef _GRAPH_H
2 #define _GRAPH_H
3
4 #include "linked_list.h"
5
6
7
8
10
11
12
13
14
A
15
16
17
18
19
20
21
22
23
24
25
26
27
35
36
37
20
38
So
39
10
40
/* a graph represented as an adjacency List */
typedef LinkedList Graph;
41
42
43
44
/* each node in the adjacency List stores a vertex */
/* a vertex has a unique numerical id */
/* and stores a List of edges from the vertex */
typedef struct Vertex {
47
48
10
49
int id;
LinkedList sedges;
> Vertex;
Graph *init_graph(void);
void free_graph(Graph *);
28 void print_graph(Graph *);
/* each node in the list of edges for a vertex store the edge weight */
/* and the destination vertex */
typedef struct Edge {
29 Vertex *find_vertex (Graph *, int);
30
Vertex *add_vertex (Graph *, int);
31
void remove_vertex (Graph *, int);
32 Edge *add_edge (Graph *, int, int, double);
33 void add_edge_undirected (Graph *, int, int, double);
34 void remove_edge (Graph *, int, int);
void remove_edges (Graph *, int);
double weight;
Vertex *vertex;
} Edge;
/* function prototypes /
Vertex *init_vertex(int);
void free_vertex (Vertex *);
Edge *init_edge (void);
void free edge (Edge *);
int *get_vertices (Graph *, int *);
Edge **get_edges (Graph *, Vertex *, int *);
Edge *get_edge (Graph *, int, int);
45
46 int edge destination (Edge *);
double edge_weight (Edge *);
#endif
Open in Web IDE
Replace
Delete
Transcribed Image Text:h graph.h 1.16 KB 1 #ifndef _GRAPH_H 2 #define _GRAPH_H 3 4 #include "linked_list.h" 5 6 7 8 10 11 12 13 14 A 15 16 17 18 19 20 21 22 23 24 25 26 27 35 36 37 20 38 So 39 10 40 /* a graph represented as an adjacency List */ typedef LinkedList Graph; 41 42 43 44 /* each node in the adjacency List stores a vertex */ /* a vertex has a unique numerical id */ /* and stores a List of edges from the vertex */ typedef struct Vertex { 47 48 10 49 int id; LinkedList sedges; > Vertex; Graph *init_graph(void); void free_graph(Graph *); 28 void print_graph(Graph *); /* each node in the list of edges for a vertex store the edge weight */ /* and the destination vertex */ typedef struct Edge { 29 Vertex *find_vertex (Graph *, int); 30 Vertex *add_vertex (Graph *, int); 31 void remove_vertex (Graph *, int); 32 Edge *add_edge (Graph *, int, int, double); 33 void add_edge_undirected (Graph *, int, int, double); 34 void remove_edge (Graph *, int, int); void remove_edges (Graph *, int); double weight; Vertex *vertex; } Edge; /* function prototypes / Vertex *init_vertex(int); void free_vertex (Vertex *); Edge *init_edge (void); void free edge (Edge *); int *get_vertices (Graph *, int *); Edge **get_edges (Graph *, Vertex *, int *); Edge *get_edge (Graph *, int, int); 45 46 int edge destination (Edge *); double edge_weight (Edge *); #endif Open in Web IDE Replace Delete
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education