CS 2123001 Data Structures Instructor Dr Turgay Korkmaz Home

CS 2123-001 Data Structures Instructor Dr. Turgay Korkmaz Homework 6 Due date: check BB Learn NO LATE HOMEWORK WILL BE ACCEPTED (Graphs graph functions You are given the basic code that we implemented in the slides to create/read print graphs. First copy/paste it into a file say graph.c and compile run it. gcc graph. o graph. .c graph graph filename For sample graphs again copyipaste the below graph data into a file undirected graphl txt and directedgraphl. txt then run your program as graph undirectedgraph1. txt graph directedgraph1. txt undirected graph1. txt directed graph1. txt 6 a 0 6 8 l 2 3 2 3 1 2 3 1 3 1 6 15 3 1 5 3 1 66 4 E 6 56 1 5 1 After studying and understanding the given code, first modify insert edge function so that it can keep the link list sorted w.rt. neighbor IDs. Second implement graph copy to create a copy of the given graph. User will call the original graph as mygl and the copy as myg2, for which we use the same pointer names in the program. Now extend the main function so that it can asks user to enter various commands ina loop and performs these commands on the related graphs. Accordingly you also need to implement those functions and call them. Finally when ending the main function, make sure you free the graphs.

Solution

void insert_edge(graphT *g, int x, int y, int w)
{
edgenodeT *pe;
pe = malloc(sizeof(edgenodeT)); // check if NULL
pe->weight = w;
pe->y = y;

pe->next = g->edges[x];
g->edges[x] = pe;

g->degree[x]++;
g->nedges++;
}

 CS 2123-001 Data Structures Instructor Dr. Turgay Korkmaz Homework 6 Due date: check BB Learn NO LATE HOMEWORK WILL BE ACCEPTED (Graphs graph functions You are

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site