Need C help

Bluga

Banned
Nov 28, 2000
4,315
0
0
This is the code for inserting Vertex and connect edges for GRAPH. I was wondering why do we need two task poiinters (task1, task2) for creating Vertex and deleting edges. For example, the following code creates two Vertex: A, B and establishes an edge between A and B. Thanks for any help.


/**********************************************/


int main(int argc, char **argv) {

Graph graph;

DfsVertex *task,
task1,
*task2;

List list;

ListElmt *element;

char data1[STRSIZ];

int i;

/*-----------------Initialize the graph-------------------------*/

graph_init(&graph, match_task, destroy_task);


/*----------- Insert Vertex A and B-----------------------*/

if ((task = (DfsVertex *)malloc(sizeof(DfsVertex))) == NULL)
return 1;

if ((task->data = malloc(STRSIZ)) == NULL)
return 1;

strcpy((char *)task->data, "A");
fprintf(stdout, "Inserting vertex %s\n", (char *)task->data);

if (graph_ins_vertex(&graph, task) != 0)
return 1;

if ((task = (DfsVertex *)malloc(sizeof(DfsVertex))) == NULL)
return 1;

if ((task->data = malloc(STRSIZ)) == NULL)
return 1;

strcpy((char *)task->data, "B");
fprintf(stdout, "Inserting vertex %s\n", (char *)task->data);

if (graph_ins_vertex(&graph, task) != 0)
return 1;

/*-------------Inserts the edge between A and B ------------------*/

task1.data = data1;

if ((task2 = (DfsVertex *)malloc(sizeof(DfsVertex))) == NULL)
return 1;

if ((task2->data = malloc(STRSIZ)) == NULL)
return 1;

strcpy((char *)task1.data, "A");
strcpy((char *)task2->data, "C");
fprintf(stdout, "Inserting edge %s to %s\n", (char *)task1.data, (char *)
task2->data);

if (graph_ins_edge(&graph, &task1, task2) != 0)
return 1;