SlideShare a Scribd company logo
1 of 10
Download to read offline
The graph above is just an example that shows the differences in distance like 5 to 6 is 1. It
doesnt matter to this proggram just a visual representation.
1 2 3 is one of the numbers on there. number 1 to number 2 has a distance of 3
//example of graph in program
I need help with the functions I'm supposed to put in
* insert [myg1 | myg2] x y w
* delete [myg1 | myg2] x y
* printgraph [myg1 | myg2]
* printdegree [myg1 | myg2] // if directed, print both in- and out-degree
* printcomplement [myg1 | myg2]
* eliminatelinks [myg1 | myg2] minW maxW
* differentlinks [myg1 | myg2] [myg1 | myg2]
* commonlinks [myg1 | myg2] [myg1 | myg2]
* dfs_print [myg1 | myg2] x
* bfs_print [myg1 | myg2] x
* isconnected [myg1 | myg2]
* numofconncomp [myg1 | myg2] * quit
//myg1 and myg2 are seperate. you can change just one graph at a time so the user must be asked
which one they want to change. Also you can copy myg1 over to myg2. Like the picture you can
make them completely different such as adding or deleting one on myg1 but leaving myg2 alone
here is the program so far. I just need to program and put in those function. I need to make it so
the user can pick what they want to do but I can program that myself. it's just programming the
above functions. I put clarifications of them at the bottom.
graph.c program
#include
#include
typedef enum {FALSE, TRUE} bool;
#define MAXV 100
typedef struct edgenode{
int y;
int weight;
struct edgenode *next;
} edgenodeT;
typedef struct{
edgenodeT *edges[MAXV+1];
int degree[MAXV+1];
int nvertices;
int nedges;
bool directed;
} graphT;
void initialize_graph(graphT *g, bool directed);
void read_graph(graphT *g, char *filename);
void insert_edge(graphT *g, int x, int y, int w);
void print_graph(graphT *g, char *name);
void free_graph(graphT *g);
graphT *copy_graph(graphT *g);
main()
// Assume that MAXV is 6
{
graphT *myg1 = NULL, *myg2 = NULL;
if(argc < 2){
fprintf(stderr, "Usage: %s graph_filename", argv[0]);
exit(-1);
}
myg1 = (graphT *) malloc(sizeof(graphT));
if (myg1==NULL) {
fprintf(stderr, "Cannot allocate memory for the graph");
exit(-1);
}
initialize_graph(myg1, FALSE);
read_graph(myg1, argv[1]);
print_graph(myg1, "myg1");
myg2 = copy_graph(myg1);
print_graph(myg2, "myg2");
// NOW in a loop get commands and
// call related functions to perform them...
free_graph(myg1);
}
initialize_graph (graphT*g, bool directed)
{
int i;
g->nvertices= 0;
g->nedges= 0;
g->directed = directed;
for (i=1; i<=MAXV; i++)
g->edges[i] = NULL;
for(i=1; i<=MAXV; i++)
g->degree[i] = 0;
}
read_graph(graphT *g)
{
int i;
int n, m, dir;
int x, y, w;
FILE *fp
if((fp=fopen(filename,"r"))==NULL){
fprintf(stderr, "Cannot open the graph file");
exit(-1);
}
scanf(”%d %d %d”, &n, &m, &dir);
g->nvertices= n;
g->nedges= 0;
g->directed= dir;
for (i=1; i<=m; i++) {
scanf(”%d %d %d”, &x, &y, &w);
insert _edge(g, x, y, w);
if(dir==FALSE)
insert _edge(g, y, x, w);
}
fclose(fp);
}
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++;
}
print_graph (graphT *g, char *name)
{
edgenodeT *pe;
int i;
if(!g) return;
printf("Graph Name: %s ", name);
for(i=1; i<=g->nvertices; i++){
printf("Node %d: ", i);
pe = g->edges[i];
while(ge){
printf(" %d %d,", pe->y, pe->weight);
pe = pe->next;
}
printf(" ");
}
}
free_graph(graphT *g)
{
edgenodeT *pe, *olde;
int i;
for(i=1; i<=g->nvertices;i++){
pe = g->edges[i];
while(pe){
olde = ps;
pe = pe->next;
free(olde);
}
}
free(g);
}
graphT *copy_graph(graphT *g)
{
graphT *newg;
newg = g;
return newg;
}
here are some clarifications
* insert myg1 3 4 20
insert a new edge 3-4 into myg1 graph with weight of 20. If this is an undirected graph also
insert edge 4-3 with weight 20. If that edge is already in the graph, don't insert anything...
* delete myg1 2 4
delete edge 2-4 from myg1. If this is an undirected graph also delete edge 4-2. If that edge is not
in the graph, don't delete anything...
* printgraph myg1
print graph using the code given...'
* printdegree myg1
if myg1 is undirected, then simply count the number of neighbors in the adjacency list for each
node and print that number as the degree of each node..
if the graph is directed, then again you can simply count the number of neighbors in the
adjacency list for each node and print that number as the out-degree of each node... BUT you
also need to find in-degree. For this, you can check every node (say node i)and count how many
times node i appears in the all adjacency lists, and print that count as the in degree or node i.
* print complement myg2
First create the complement graph of myg2 as cg, and call printgraph(cg) then free complement
graph cg.
* eliminatelinks myg1 minW maxW
check each edge pe
if (pe->w < minW || pe->w > maxW) delete that edge
* differentlinks myg1 myg2
print edges that are in my g1 but not in my g2
* commonlinks myg1 myg2
print edges that are both in my g1 and in myg2
* dfs_print myg1 x
print in which order nodes are visited then for each node print the path from x to that node
* bfs_print myg2 x
print in which order nodes are visited then for each node print the path from x to that node
* isconnected myg1
* numofconncomp myg2 graph. txt zive. txt 1, takt.
Solution
#include
#include
typedef enum {FALSE, TRUE} bool;
#define MAXV 100;
typedef struct edgenode
{
int y;
int weight;
struct edgenode *next;
} edgenodeT;
typedef struct
{
edgenodeT *edges[MAXV+1];
int degree[MAXV+1];
int nvertices;
int nedges;
bool directed;
} graphT;
void initialize_graph(graphT *g, bool directed);
void read_graph(graphT *g, char *filename);
void insert_edge(graphT *g, int x, int y, int w);
void print_graph(graphT *g, char *name);
void free_graph(graphT *g);
graphT *copy_graph(graphT *g);
main()
// Assume that MAXV is 6
{
int ch;
switch(ch)
{
Case ‘1’:Printf(“1.Press 1 for 1st Graph::”);
Scanf(“%d”,ch);
Break;
Case ‘2’:printf(“2.Press 2 for 2nd Graph:”);
Scanf(“%d”,ch);
Break;
Case ‘3’:printf(“3.For Display Grpah :”);
If(ch==3)
{
Print_graph();
}
Break;
Exit(0);
}
graphT *myg1 = NULL, *myg2 = NULL;
if(argc < 2)
{
fprintf(stderr, "Usage: %s graph_filename", argv[0]);
exit(-1);
}
myg1 = (graphT *) malloc(sizeof(graphT));
if (myg1==NULL)
{
fprintf(stderr, "Cannot allocate memory for the graph");
exit(-1);
}
initialize_graph(myg1, FALSE);
read_graph(myg1, argv[1]);
print_graph(myg1, "myg1");
myg2 = copy_graph(myg1);
print_graph(myg2, "myg2");
// NOW in a loop get commands and
// call related functions to perform them...
free_graph(myg1);
}
initialize_graph (graphT*g, bool directed)
{
int i;
g->nvertices= 0;
g->nedges= 0;
g->directed = directed;
for (i=1; i<=MAXV; i++)
g->edges[i] = NULL;
for(i=1; i<=MAXV; i++)
g->degree[i] = 0;
}
read_graph(graphT *g)
{
int i;
int n, m, dir;
int x, y, w;
FILE *fp
if((fp=fopen(filename,"r"))==NULL)
{
fprintf(stderr, "Cannot open the graph file");
exit(-1);
}
scanf(”%d %d %d”, &n, &m, &dir);
g->nvertices= n;
g->nedges= 0;
g->directed= dir;
for (i=1; i<=m; i++)
{
scanf(”%d %d %d”, &x, &y, &w);
insert _edge(g, x, y, w);
if(dir==FALSE)
insert _edge(g, y, x, w);
}
fclose(fp);
}
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]++;
->nedges++;
}
print_graph (graphT *g, char *name)
{
edgenodeT *pe;
int i;
if(!g) return;
printf("Graph Name: %s ", name);
for(i=1; i<=g->nvertices; i++)
{
printf("Node %d: ", i);
pe = g->edges[i];
while(ge)
{
printf(" %d t %d,", pe->y, pe->weight);
pe = pe->next;
}
printf(" ");
}
}
Void display()
{
Printf(“******Graph 1*******”);
for(i=1; i<=g->nvertices; i++)
{
printf("Node  %d: "  , i);
pe = g->edges[i];
}
Printf(*****Grpah2******);
for(i=1; i<=g->nvertices; i++)
{
printf("Node  %d  : ", i);
pe = g->edges[i];
}
free_graph(graphT *g)
{
edgenodeT *pe, *olde;
int i;
for(i=1; i<=g->nvertices;i++)
{
pe = g->edges[i];
while(pe){
olde = ps;
pe = pe->next;
free(olde);
}
}
free(g);
}
graphT *copy_graph(graphT *g)
{
graphT *newg;
newg = g;
return newg;
}

More Related Content

Similar to The graph above is just an example that shows the differences in dis.pdf

2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
Ghana National Flag
Ghana National FlagGhana National Flag
Ghana National FlagSH Rajøn
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfaptcomputerzone
 
Elastic response pseudo spectrum in c programming
Elastic response pseudo spectrum in c programmingElastic response pseudo spectrum in c programming
Elastic response pseudo spectrum in c programmingSalar Delavar Qashqai
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfaquazac
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicssnelkoli
 
Lab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsLab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsRup Chowdhury
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfabdulrahamanbags
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfanyacarpets
 
[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R台灣資料科學年會
 
square.cpp Open
 square.cpp Open square.cpp Open
square.cpp OpenMikeEly930
 

Similar to The graph above is just an example that shows the differences in dis.pdf (20)

2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
Drawing Figures
Drawing FiguresDrawing Figures
Drawing Figures
 
Ghana National Flag
Ghana National FlagGhana National Flag
Ghana National Flag
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 
Elastic response pseudo spectrum in c programming
Elastic response pseudo spectrum in c programmingElastic response pseudo spectrum in c programming
Elastic response pseudo spectrum in c programming
 
201707 SER332 Lecture 05
201707 SER332 Lecture 05   201707 SER332 Lecture 05
201707 SER332 Lecture 05
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Lab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsLab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer Graphics
 
Functions
FunctionsFunctions
Functions
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R
 
05-Debug.pdf
05-Debug.pdf05-Debug.pdf
05-Debug.pdf
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
 
square.cpp Open
 square.cpp Open square.cpp Open
square.cpp Open
 
Python grass
Python grassPython grass
Python grass
 
Distributed computing with spark
Distributed computing with sparkDistributed computing with spark
Distributed computing with spark
 

More from jyothimuppasani1

How does an open source operating system like Linux® affect Internet.pdf
How does an open source operating system like Linux® affect Internet.pdfHow does an open source operating system like Linux® affect Internet.pdf
How does an open source operating system like Linux® affect Internet.pdfjyothimuppasani1
 
Help please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfHelp please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfjyothimuppasani1
 
how can I replace the Newsfeed text with a custom on in SharePoi.pdf
how can I replace the Newsfeed text with a custom on in SharePoi.pdfhow can I replace the Newsfeed text with a custom on in SharePoi.pdf
how can I replace the Newsfeed text with a custom on in SharePoi.pdfjyothimuppasani1
 
Hello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdfHello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdfjyothimuppasani1
 
For each of the following reseach questions identify the observation.pdf
For each of the following reseach questions identify the observation.pdfFor each of the following reseach questions identify the observation.pdf
For each of the following reseach questions identify the observation.pdfjyothimuppasani1
 
Find an Eulerian trail in the following graph. Be sure to indicate th.pdf
Find an Eulerian trail in the following graph. Be sure to indicate th.pdfFind an Eulerian trail in the following graph. Be sure to indicate th.pdf
Find an Eulerian trail in the following graph. Be sure to indicate th.pdfjyothimuppasani1
 
File encryption. [32] Write a program which accepts a filename as a .pdf
File encryption. [32] Write a program which accepts a filename as a .pdfFile encryption. [32] Write a program which accepts a filename as a .pdf
File encryption. [32] Write a program which accepts a filename as a .pdfjyothimuppasani1
 
Explain the relevance that medical standards of practice have to one.pdf
Explain the relevance that medical standards of practice have to one.pdfExplain the relevance that medical standards of practice have to one.pdf
Explain the relevance that medical standards of practice have to one.pdfjyothimuppasani1
 
Find the mission and values statements for four different hospita.pdf
Find the mission and values statements for four different hospita.pdfFind the mission and values statements for four different hospita.pdf
Find the mission and values statements for four different hospita.pdfjyothimuppasani1
 
Did colonial rule freeze colonized societies by preserving old s.pdf
Did colonial rule freeze colonized societies by preserving old s.pdfDid colonial rule freeze colonized societies by preserving old s.pdf
Did colonial rule freeze colonized societies by preserving old s.pdfjyothimuppasani1
 
Do you think that nonhuman animals have interests Does this mean th.pdf
Do you think that nonhuman animals have interests Does this mean th.pdfDo you think that nonhuman animals have interests Does this mean th.pdf
Do you think that nonhuman animals have interests Does this mean th.pdfjyothimuppasani1
 
Discuss the importance of recognizing and implementing different ent.pdf
Discuss the importance of recognizing and implementing different ent.pdfDiscuss the importance of recognizing and implementing different ent.pdf
Discuss the importance of recognizing and implementing different ent.pdfjyothimuppasani1
 
Considering the challenges she is facing, what Anitas plan before .pdf
Considering the challenges she is facing, what Anitas plan before .pdfConsidering the challenges she is facing, what Anitas plan before .pdf
Considering the challenges she is facing, what Anitas plan before .pdfjyothimuppasani1
 
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfData Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfjyothimuppasani1
 
Conceptual skills are most important at theSolutionConceptual .pdf
Conceptual skills are most important at theSolutionConceptual .pdfConceptual skills are most important at theSolutionConceptual .pdf
Conceptual skills are most important at theSolutionConceptual .pdfjyothimuppasani1
 
A variable whose scope is restricted to the method where it was decl.pdf
A variable whose scope is restricted to the method where it was decl.pdfA variable whose scope is restricted to the method where it was decl.pdf
A variable whose scope is restricted to the method where it was decl.pdfjyothimuppasani1
 
•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdfjyothimuppasani1
 
You are to write a GUI program that will allow a user to buy, sell a.pdf
You are to write a GUI program that will allow a user to buy, sell a.pdfYou are to write a GUI program that will allow a user to buy, sell a.pdf
You are to write a GUI program that will allow a user to buy, sell a.pdfjyothimuppasani1
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfjyothimuppasani1
 
What are the factors that contribute to H+ gain or loss How do lung.pdf
What are the factors that contribute to H+ gain or loss How do lung.pdfWhat are the factors that contribute to H+ gain or loss How do lung.pdf
What are the factors that contribute to H+ gain or loss How do lung.pdfjyothimuppasani1
 

More from jyothimuppasani1 (20)

How does an open source operating system like Linux® affect Internet.pdf
How does an open source operating system like Linux® affect Internet.pdfHow does an open source operating system like Linux® affect Internet.pdf
How does an open source operating system like Linux® affect Internet.pdf
 
Help please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfHelp please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdf
 
how can I replace the Newsfeed text with a custom on in SharePoi.pdf
how can I replace the Newsfeed text with a custom on in SharePoi.pdfhow can I replace the Newsfeed text with a custom on in SharePoi.pdf
how can I replace the Newsfeed text with a custom on in SharePoi.pdf
 
Hello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdfHello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdf
 
For each of the following reseach questions identify the observation.pdf
For each of the following reseach questions identify the observation.pdfFor each of the following reseach questions identify the observation.pdf
For each of the following reseach questions identify the observation.pdf
 
Find an Eulerian trail in the following graph. Be sure to indicate th.pdf
Find an Eulerian trail in the following graph. Be sure to indicate th.pdfFind an Eulerian trail in the following graph. Be sure to indicate th.pdf
Find an Eulerian trail in the following graph. Be sure to indicate th.pdf
 
File encryption. [32] Write a program which accepts a filename as a .pdf
File encryption. [32] Write a program which accepts a filename as a .pdfFile encryption. [32] Write a program which accepts a filename as a .pdf
File encryption. [32] Write a program which accepts a filename as a .pdf
 
Explain the relevance that medical standards of practice have to one.pdf
Explain the relevance that medical standards of practice have to one.pdfExplain the relevance that medical standards of practice have to one.pdf
Explain the relevance that medical standards of practice have to one.pdf
 
Find the mission and values statements for four different hospita.pdf
Find the mission and values statements for four different hospita.pdfFind the mission and values statements for four different hospita.pdf
Find the mission and values statements for four different hospita.pdf
 
Did colonial rule freeze colonized societies by preserving old s.pdf
Did colonial rule freeze colonized societies by preserving old s.pdfDid colonial rule freeze colonized societies by preserving old s.pdf
Did colonial rule freeze colonized societies by preserving old s.pdf
 
Do you think that nonhuman animals have interests Does this mean th.pdf
Do you think that nonhuman animals have interests Does this mean th.pdfDo you think that nonhuman animals have interests Does this mean th.pdf
Do you think that nonhuman animals have interests Does this mean th.pdf
 
Discuss the importance of recognizing and implementing different ent.pdf
Discuss the importance of recognizing and implementing different ent.pdfDiscuss the importance of recognizing and implementing different ent.pdf
Discuss the importance of recognizing and implementing different ent.pdf
 
Considering the challenges she is facing, what Anitas plan before .pdf
Considering the challenges she is facing, what Anitas plan before .pdfConsidering the challenges she is facing, what Anitas plan before .pdf
Considering the challenges she is facing, what Anitas plan before .pdf
 
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfData Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
 
Conceptual skills are most important at theSolutionConceptual .pdf
Conceptual skills are most important at theSolutionConceptual .pdfConceptual skills are most important at theSolutionConceptual .pdf
Conceptual skills are most important at theSolutionConceptual .pdf
 
A variable whose scope is restricted to the method where it was decl.pdf
A variable whose scope is restricted to the method where it was decl.pdfA variable whose scope is restricted to the method where it was decl.pdf
A variable whose scope is restricted to the method where it was decl.pdf
 
•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf
 
You are to write a GUI program that will allow a user to buy, sell a.pdf
You are to write a GUI program that will allow a user to buy, sell a.pdfYou are to write a GUI program that will allow a user to buy, sell a.pdf
You are to write a GUI program that will allow a user to buy, sell a.pdf
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
 
What are the factors that contribute to H+ gain or loss How do lung.pdf
What are the factors that contribute to H+ gain or loss How do lung.pdfWhat are the factors that contribute to H+ gain or loss How do lung.pdf
What are the factors that contribute to H+ gain or loss How do lung.pdf
 

Recently uploaded

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

The graph above is just an example that shows the differences in dis.pdf

  • 1. The graph above is just an example that shows the differences in distance like 5 to 6 is 1. It doesnt matter to this proggram just a visual representation. 1 2 3 is one of the numbers on there. number 1 to number 2 has a distance of 3 //example of graph in program I need help with the functions I'm supposed to put in * insert [myg1 | myg2] x y w * delete [myg1 | myg2] x y * printgraph [myg1 | myg2] * printdegree [myg1 | myg2] // if directed, print both in- and out-degree * printcomplement [myg1 | myg2] * eliminatelinks [myg1 | myg2] minW maxW * differentlinks [myg1 | myg2] [myg1 | myg2] * commonlinks [myg1 | myg2] [myg1 | myg2] * dfs_print [myg1 | myg2] x * bfs_print [myg1 | myg2] x * isconnected [myg1 | myg2] * numofconncomp [myg1 | myg2] * quit //myg1 and myg2 are seperate. you can change just one graph at a time so the user must be asked which one they want to change. Also you can copy myg1 over to myg2. Like the picture you can make them completely different such as adding or deleting one on myg1 but leaving myg2 alone here is the program so far. I just need to program and put in those function. I need to make it so the user can pick what they want to do but I can program that myself. it's just programming the above functions. I put clarifications of them at the bottom. graph.c program #include #include typedef enum {FALSE, TRUE} bool; #define MAXV 100 typedef struct edgenode{ int y; int weight; struct edgenode *next; } edgenodeT; typedef struct{ edgenodeT *edges[MAXV+1];
  • 2. int degree[MAXV+1]; int nvertices; int nedges; bool directed; } graphT; void initialize_graph(graphT *g, bool directed); void read_graph(graphT *g, char *filename); void insert_edge(graphT *g, int x, int y, int w); void print_graph(graphT *g, char *name); void free_graph(graphT *g); graphT *copy_graph(graphT *g); main() // Assume that MAXV is 6 { graphT *myg1 = NULL, *myg2 = NULL; if(argc < 2){ fprintf(stderr, "Usage: %s graph_filename", argv[0]); exit(-1); } myg1 = (graphT *) malloc(sizeof(graphT)); if (myg1==NULL) { fprintf(stderr, "Cannot allocate memory for the graph"); exit(-1); } initialize_graph(myg1, FALSE); read_graph(myg1, argv[1]); print_graph(myg1, "myg1"); myg2 = copy_graph(myg1); print_graph(myg2, "myg2"); // NOW in a loop get commands and // call related functions to perform them... free_graph(myg1); } initialize_graph (graphT*g, bool directed) { int i;
  • 3. g->nvertices= 0; g->nedges= 0; g->directed = directed; for (i=1; i<=MAXV; i++) g->edges[i] = NULL; for(i=1; i<=MAXV; i++) g->degree[i] = 0; } read_graph(graphT *g) { int i; int n, m, dir; int x, y, w; FILE *fp if((fp=fopen(filename,"r"))==NULL){ fprintf(stderr, "Cannot open the graph file"); exit(-1); } scanf(”%d %d %d”, &n, &m, &dir); g->nvertices= n; g->nedges= 0; g->directed= dir; for (i=1; i<=m; i++) { scanf(”%d %d %d”, &x, &y, &w); insert _edge(g, x, y, w); if(dir==FALSE) insert _edge(g, y, x, w); } fclose(fp); } 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;
  • 4. pe->next = g->edges[x]; g->edges[x] = pe; g->degree[x]++; g->nedges++; } print_graph (graphT *g, char *name) { edgenodeT *pe; int i; if(!g) return; printf("Graph Name: %s ", name); for(i=1; i<=g->nvertices; i++){ printf("Node %d: ", i); pe = g->edges[i]; while(ge){ printf(" %d %d,", pe->y, pe->weight); pe = pe->next; } printf(" "); } } free_graph(graphT *g) { edgenodeT *pe, *olde; int i; for(i=1; i<=g->nvertices;i++){ pe = g->edges[i]; while(pe){ olde = ps; pe = pe->next; free(olde); } } free(g); } graphT *copy_graph(graphT *g)
  • 5. { graphT *newg; newg = g; return newg; } here are some clarifications * insert myg1 3 4 20 insert a new edge 3-4 into myg1 graph with weight of 20. If this is an undirected graph also insert edge 4-3 with weight 20. If that edge is already in the graph, don't insert anything... * delete myg1 2 4 delete edge 2-4 from myg1. If this is an undirected graph also delete edge 4-2. If that edge is not in the graph, don't delete anything... * printgraph myg1 print graph using the code given...' * printdegree myg1 if myg1 is undirected, then simply count the number of neighbors in the adjacency list for each node and print that number as the degree of each node.. if the graph is directed, then again you can simply count the number of neighbors in the adjacency list for each node and print that number as the out-degree of each node... BUT you also need to find in-degree. For this, you can check every node (say node i)and count how many times node i appears in the all adjacency lists, and print that count as the in degree or node i. * print complement myg2 First create the complement graph of myg2 as cg, and call printgraph(cg) then free complement graph cg. * eliminatelinks myg1 minW maxW check each edge pe if (pe->w < minW || pe->w > maxW) delete that edge * differentlinks myg1 myg2 print edges that are in my g1 but not in my g2 * commonlinks myg1 myg2 print edges that are both in my g1 and in myg2 * dfs_print myg1 x print in which order nodes are visited then for each node print the path from x to that node * bfs_print myg2 x print in which order nodes are visited then for each node print the path from x to that node
  • 6. * isconnected myg1 * numofconncomp myg2 graph. txt zive. txt 1, takt. Solution #include #include typedef enum {FALSE, TRUE} bool; #define MAXV 100; typedef struct edgenode { int y; int weight; struct edgenode *next; } edgenodeT; typedef struct { edgenodeT *edges[MAXV+1]; int degree[MAXV+1]; int nvertices; int nedges; bool directed; } graphT; void initialize_graph(graphT *g, bool directed); void read_graph(graphT *g, char *filename); void insert_edge(graphT *g, int x, int y, int w); void print_graph(graphT *g, char *name); void free_graph(graphT *g); graphT *copy_graph(graphT *g); main() // Assume that MAXV is 6 { int ch; switch(ch) { Case ‘1’:Printf(“1.Press 1 for 1st Graph::”);
  • 7. Scanf(“%d”,ch); Break; Case ‘2’:printf(“2.Press 2 for 2nd Graph:”); Scanf(“%d”,ch); Break; Case ‘3’:printf(“3.For Display Grpah :”); If(ch==3) { Print_graph(); } Break; Exit(0); } graphT *myg1 = NULL, *myg2 = NULL; if(argc < 2) { fprintf(stderr, "Usage: %s graph_filename", argv[0]); exit(-1); } myg1 = (graphT *) malloc(sizeof(graphT)); if (myg1==NULL) { fprintf(stderr, "Cannot allocate memory for the graph"); exit(-1); } initialize_graph(myg1, FALSE); read_graph(myg1, argv[1]); print_graph(myg1, "myg1"); myg2 = copy_graph(myg1); print_graph(myg2, "myg2"); // NOW in a loop get commands and // call related functions to perform them... free_graph(myg1); } initialize_graph (graphT*g, bool directed)
  • 8. { int i; g->nvertices= 0; g->nedges= 0; g->directed = directed; for (i=1; i<=MAXV; i++) g->edges[i] = NULL; for(i=1; i<=MAXV; i++) g->degree[i] = 0; } read_graph(graphT *g) { int i; int n, m, dir; int x, y, w; FILE *fp if((fp=fopen(filename,"r"))==NULL) { fprintf(stderr, "Cannot open the graph file"); exit(-1); } scanf(”%d %d %d”, &n, &m, &dir); g->nvertices= n; g->nedges= 0; g->directed= dir; for (i=1; i<=m; i++) { scanf(”%d %d %d”, &x, &y, &w); insert _edge(g, x, y, w); if(dir==FALSE) insert _edge(g, y, x, w); } fclose(fp); } insert_edge(graphT *g, int x, int y, int w) {
  • 9. 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]++; ->nedges++; } print_graph (graphT *g, char *name) { edgenodeT *pe; int i; if(!g) return; printf("Graph Name: %s ", name); for(i=1; i<=g->nvertices; i++) { printf("Node %d: ", i); pe = g->edges[i]; while(ge) { printf(" %d t %d,", pe->y, pe->weight); pe = pe->next; } printf(" "); } } Void display() { Printf(“******Graph 1*******”); for(i=1; i<=g->nvertices; i++) { printf("Node %d: " , i); pe = g->edges[i]; }
  • 10. Printf(*****Grpah2******); for(i=1; i<=g->nvertices; i++) { printf("Node %d : ", i); pe = g->edges[i]; } free_graph(graphT *g) { edgenodeT *pe, *olde; int i; for(i=1; i<=g->nvertices;i++) { pe = g->edges[i]; while(pe){ olde = ps; pe = pe->next; free(olde); } } free(g); } graphT *copy_graph(graphT *g) { graphT *newg; newg = g; return newg; }