SlideShare a Scribd company logo
1 of 9
Download to read offline
implement the following funtions. myg1 and myg2 are seperate. x and y represent the two points
in the graph and w is the distance. after implementing ask the user to choose which funtion they
would like to use.
* 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
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
Solution
#include
#define max 20
int adj[ max ][ max ];
int n;
main()
{
int choice;
int node, origin, destin;
create_graph();
while ( 1 )
{
printf( "1.Insert a node " );
printf( "2.Insert an edge " );
printf( "3.Delete a node " );
printf( "4.Delete an edge " );
printf( "5.Dispaly " );
printf( "6.Exit " );
printf( "Enter your choice : " );
scanf( "%d", &choice );
switch ( choice )
{
case 1:
insert_node();
break;
case 2:
printf( "Enter an edge to be inserted : " );
fflush( stdin );
scanf( "%d %d", &origin, &destin );
insert_edge( origin, destin );
break;
case 3:
printf( "Enter a node to be deleted : " );
fflush( stdin );
scanf( "%d", &node );
delete_node( node );
break;
case 4:
printf( "Enter an edge to be deleted : " );
fflush( stdin );
scanf( "%d %d", &origin, &destin );
del_edge( origin, destin );
break;
case 5:
display();
break;
case 6:
exit();
default:
printf( "Wrong choice " );
break;
} } }
create_graph()
{
int i, max_edges, origin, destin;
printf( "Enter number of nodes : " );
scanf( "%d", &n );
max_edges = n * ( n – 1 );
for ( i = 1;i <= max_edges;i++ )
{
printf( "Enter edge %d( 0 0 ) to quit : ", i );
scanf( "%d %d", &origin, &destin );
if ( ( origin == 0 ) && ( destin == 0 ) )
break;
if ( origin > n || destin > n || origin <= 0 || destin <= 0 )
{
printf( "Invalid edge! " );
i–;
}
else
adj[ origin ][ destin ] = 1;
} /*End of for*/
} /*End of create_graph()*/
display()
{
int i, j;
for ( i = 1;i <= n;i++ )
{
for ( j = 1;j <= n;j++ )
printf( "%4d", adj[ i ][ j ] );
printf( " " );
}
} /*End of display()*/
insert_node()
{
int i;
n++; /*Increase number of nodes in the graph*/
printf( "The inserted node is %d  ", n );
for ( i = 1;i <= n;i++ )
{
adj[ i ][ n ] = 0;
adj[ n ][ i ] = 0;
}
} /*End of insert_node()*/
delete_node( char u )
{
int i, j;
if ( n == 0 )
{
printf( "Graph is empty " );
return ;
}
if ( u > n )
{
printf( "This node is not present in the graph " );
return ;
}
for ( i = u;i <= n – 1;i++ )
for ( j = 1;j <= n;j++ )
{
adj[ j ][ i ] = adj[ j ][ i + 1 ];
adj[ i ][ j ] = adj[ i + 1 ][ j ];
}
n–; /*Decrease the number of nodes in the graph */
} /*End of delete_node*/
insert_edge( char u, char v )
{
if ( u > n )
{
printf( "Source node does not exist " );
return ;
}
if ( v > n )
{
printf( "Destination node does not exist " );
return ;
}
adj[ u ][ v ] = 1;
} /*End of insert_edge()*/
del_edge( char u, char v )
{
if ( u > n || v > n || adj[ u ][ v ] == 0 )
{
printf( "This edge does not exist " );
return ;
}
adj[ u ][ v ] = 0;
} /*End of del_edge()*/

More Related Content

Similar to implement the following funtions. myg1 and myg2 are seperate. x and .pdf

Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
PART 4: GEOGRAPHIC SCRIPTING
PART 4: GEOGRAPHIC SCRIPTINGPART 4: GEOGRAPHIC SCRIPTING
PART 4: GEOGRAPHIC SCRIPTINGAndrea Antonello
 
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
 
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
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?jonbodner
 
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
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics FunctionsSHAKOOR AB
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewMarkus Schneider
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdfanandmobile
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7alish sha
 

Similar to implement the following funtions. myg1 and myg2 are seperate. x and .pdf (20)

Drawing Figures
Drawing FiguresDrawing Figures
Drawing Figures
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
PART 4: GEOGRAPHIC SCRIPTING
PART 4: GEOGRAPHIC SCRIPTINGPART 4: GEOGRAPHIC SCRIPTING
PART 4: GEOGRAPHIC SCRIPTING
 
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
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
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
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 
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
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
 
Functions
FunctionsFunctions
Functions
 
Encoder + decoder
Encoder + decoderEncoder + decoder
Encoder + decoder
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / Overview
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Отладка в GDB
Отладка в GDBОтладка в GDB
Отладка в GDB
 

More from forladies

You isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
You isolated an enveloped RNA virus. Purified RNA is not capable of .pdfYou isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
You isolated an enveloped RNA virus. Purified RNA is not capable of .pdfforladies
 
What properties should the following molecules NOT have in common (S.pdf
What properties should the following molecules NOT have in common (S.pdfWhat properties should the following molecules NOT have in common (S.pdf
What properties should the following molecules NOT have in common (S.pdfforladies
 
What is the difference between Schedule C and Schedule E income (i.e.pdf
What is the difference between Schedule C and Schedule E income (i.e.pdfWhat is the difference between Schedule C and Schedule E income (i.e.pdf
What is the difference between Schedule C and Schedule E income (i.e.pdfforladies
 
What are the ethical and legal concerns associated with managing tel.pdf
What are the ethical and legal concerns associated with managing tel.pdfWhat are the ethical and legal concerns associated with managing tel.pdf
What are the ethical and legal concerns associated with managing tel.pdfforladies
 
Using the Graphical User Interface (GUI)Create a user nam.pdf
Using the Graphical User Interface (GUI)Create a user nam.pdfUsing the Graphical User Interface (GUI)Create a user nam.pdf
Using the Graphical User Interface (GUI)Create a user nam.pdfforladies
 
The adjusting entry to record the salaries earned due to employees f.pdf
The adjusting entry to record the salaries earned due to employees f.pdfThe adjusting entry to record the salaries earned due to employees f.pdf
The adjusting entry to record the salaries earned due to employees f.pdfforladies
 
TF A document type definition (DTD) can be referenced by many Exten.pdf
TF A document type definition (DTD) can be referenced by many Exten.pdfTF A document type definition (DTD) can be referenced by many Exten.pdf
TF A document type definition (DTD) can be referenced by many Exten.pdfforladies
 
Summarize the first and the second checkpoints during T cell develop.pdf
Summarize the first and the second checkpoints during T cell develop.pdfSummarize the first and the second checkpoints during T cell develop.pdf
Summarize the first and the second checkpoints during T cell develop.pdfforladies
 
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdfPLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdfforladies
 
Please answer the following at the bottom of the case. ThanksTo ne.pdf
Please answer the following at the bottom of the case. ThanksTo ne.pdfPlease answer the following at the bottom of the case. ThanksTo ne.pdf
Please answer the following at the bottom of the case. ThanksTo ne.pdfforladies
 
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdfMitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdfforladies
 
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdf
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdfLearn the genetics vocabulary (see HW4)] For each of the following ge.pdf
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdfforladies
 
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdfIf nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdfforladies
 
Investments in trade securities are always short term investments. T.pdf
Investments in trade securities are always short term investments. T.pdfInvestments in trade securities are always short term investments. T.pdf
Investments in trade securities are always short term investments. T.pdfforladies
 
Information Securityfind an article online discussing defense-in-d.pdf
Information Securityfind an article online discussing defense-in-d.pdfInformation Securityfind an article online discussing defense-in-d.pdf
Information Securityfind an article online discussing defense-in-d.pdfforladies
 
If two peers share a link in the overlay (they are neighbors in the .pdf
If two peers share a link in the overlay (they are neighbors in the .pdfIf two peers share a link in the overlay (they are neighbors in the .pdf
If two peers share a link in the overlay (they are neighbors in the .pdfforladies
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfforladies
 
how important is Negative Emotionality to an accounting career plea.pdf
how important is Negative Emotionality to an accounting career plea.pdfhow important is Negative Emotionality to an accounting career plea.pdf
how important is Negative Emotionality to an accounting career plea.pdfforladies
 
How do I know whether miscellaneous expense goes on top or bottom of.pdf
How do I know whether miscellaneous expense goes on top or bottom of.pdfHow do I know whether miscellaneous expense goes on top or bottom of.pdf
How do I know whether miscellaneous expense goes on top or bottom of.pdfforladies
 
Given a 1024 by 1024 RAM block, answer the following questions a) If.pdf
Given a 1024 by 1024 RAM block, answer the following questions  a) If.pdfGiven a 1024 by 1024 RAM block, answer the following questions  a) If.pdf
Given a 1024 by 1024 RAM block, answer the following questions a) If.pdfforladies
 

More from forladies (20)

You isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
You isolated an enveloped RNA virus. Purified RNA is not capable of .pdfYou isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
You isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
 
What properties should the following molecules NOT have in common (S.pdf
What properties should the following molecules NOT have in common (S.pdfWhat properties should the following molecules NOT have in common (S.pdf
What properties should the following molecules NOT have in common (S.pdf
 
What is the difference between Schedule C and Schedule E income (i.e.pdf
What is the difference between Schedule C and Schedule E income (i.e.pdfWhat is the difference between Schedule C and Schedule E income (i.e.pdf
What is the difference between Schedule C and Schedule E income (i.e.pdf
 
What are the ethical and legal concerns associated with managing tel.pdf
What are the ethical and legal concerns associated with managing tel.pdfWhat are the ethical and legal concerns associated with managing tel.pdf
What are the ethical and legal concerns associated with managing tel.pdf
 
Using the Graphical User Interface (GUI)Create a user nam.pdf
Using the Graphical User Interface (GUI)Create a user nam.pdfUsing the Graphical User Interface (GUI)Create a user nam.pdf
Using the Graphical User Interface (GUI)Create a user nam.pdf
 
The adjusting entry to record the salaries earned due to employees f.pdf
The adjusting entry to record the salaries earned due to employees f.pdfThe adjusting entry to record the salaries earned due to employees f.pdf
The adjusting entry to record the salaries earned due to employees f.pdf
 
TF A document type definition (DTD) can be referenced by many Exten.pdf
TF A document type definition (DTD) can be referenced by many Exten.pdfTF A document type definition (DTD) can be referenced by many Exten.pdf
TF A document type definition (DTD) can be referenced by many Exten.pdf
 
Summarize the first and the second checkpoints during T cell develop.pdf
Summarize the first and the second checkpoints during T cell develop.pdfSummarize the first and the second checkpoints during T cell develop.pdf
Summarize the first and the second checkpoints during T cell develop.pdf
 
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdfPLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
 
Please answer the following at the bottom of the case. ThanksTo ne.pdf
Please answer the following at the bottom of the case. ThanksTo ne.pdfPlease answer the following at the bottom of the case. ThanksTo ne.pdf
Please answer the following at the bottom of the case. ThanksTo ne.pdf
 
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdfMitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
 
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdf
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdfLearn the genetics vocabulary (see HW4)] For each of the following ge.pdf
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdf
 
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdfIf nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
 
Investments in trade securities are always short term investments. T.pdf
Investments in trade securities are always short term investments. T.pdfInvestments in trade securities are always short term investments. T.pdf
Investments in trade securities are always short term investments. T.pdf
 
Information Securityfind an article online discussing defense-in-d.pdf
Information Securityfind an article online discussing defense-in-d.pdfInformation Securityfind an article online discussing defense-in-d.pdf
Information Securityfind an article online discussing defense-in-d.pdf
 
If two peers share a link in the overlay (they are neighbors in the .pdf
If two peers share a link in the overlay (they are neighbors in the .pdfIf two peers share a link in the overlay (they are neighbors in the .pdf
If two peers share a link in the overlay (they are neighbors in the .pdf
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
how important is Negative Emotionality to an accounting career plea.pdf
how important is Negative Emotionality to an accounting career plea.pdfhow important is Negative Emotionality to an accounting career plea.pdf
how important is Negative Emotionality to an accounting career plea.pdf
 
How do I know whether miscellaneous expense goes on top or bottom of.pdf
How do I know whether miscellaneous expense goes on top or bottom of.pdfHow do I know whether miscellaneous expense goes on top or bottom of.pdf
How do I know whether miscellaneous expense goes on top or bottom of.pdf
 
Given a 1024 by 1024 RAM block, answer the following questions a) If.pdf
Given a 1024 by 1024 RAM block, answer the following questions  a) If.pdfGiven a 1024 by 1024 RAM block, answer the following questions  a) If.pdf
Given a 1024 by 1024 RAM block, answer the following questions a) If.pdf
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
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
 
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
 
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
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
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
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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🔝
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
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
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
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
 
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
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
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
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
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
 
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
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

implement the following funtions. myg1 and myg2 are seperate. x and .pdf

  • 1. implement the following funtions. myg1 and myg2 are seperate. x and y represent the two points in the graph and w is the distance. after implementing ask the user to choose which funtion they would like to use. * 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 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;
  • 2. 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;
  • 3. 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]++;
  • 4. 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;
  • 5. 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
  • 6. Solution #include #define max 20 int adj[ max ][ max ]; int n; main() { int choice; int node, origin, destin; create_graph(); while ( 1 ) { printf( "1.Insert a node " ); printf( "2.Insert an edge " ); printf( "3.Delete a node " ); printf( "4.Delete an edge " ); printf( "5.Dispaly " ); printf( "6.Exit " ); printf( "Enter your choice : " ); scanf( "%d", &choice ); switch ( choice ) { case 1: insert_node(); break; case 2: printf( "Enter an edge to be inserted : " ); fflush( stdin ); scanf( "%d %d", &origin, &destin ); insert_edge( origin, destin ); break; case 3: printf( "Enter a node to be deleted : " ); fflush( stdin ); scanf( "%d", &node );
  • 7. delete_node( node ); break; case 4: printf( "Enter an edge to be deleted : " ); fflush( stdin ); scanf( "%d %d", &origin, &destin ); del_edge( origin, destin ); break; case 5: display(); break; case 6: exit(); default: printf( "Wrong choice " ); break; } } } create_graph() { int i, max_edges, origin, destin; printf( "Enter number of nodes : " ); scanf( "%d", &n ); max_edges = n * ( n – 1 ); for ( i = 1;i <= max_edges;i++ ) { printf( "Enter edge %d( 0 0 ) to quit : ", i ); scanf( "%d %d", &origin, &destin ); if ( ( origin == 0 ) && ( destin == 0 ) ) break; if ( origin > n || destin > n || origin <= 0 || destin <= 0 ) { printf( "Invalid edge! " ); i–; } else adj[ origin ][ destin ] = 1;
  • 8. } /*End of for*/ } /*End of create_graph()*/ display() { int i, j; for ( i = 1;i <= n;i++ ) { for ( j = 1;j <= n;j++ ) printf( "%4d", adj[ i ][ j ] ); printf( " " ); } } /*End of display()*/ insert_node() { int i; n++; /*Increase number of nodes in the graph*/ printf( "The inserted node is %d ", n ); for ( i = 1;i <= n;i++ ) { adj[ i ][ n ] = 0; adj[ n ][ i ] = 0; } } /*End of insert_node()*/ delete_node( char u ) { int i, j; if ( n == 0 ) { printf( "Graph is empty " ); return ; } if ( u > n ) { printf( "This node is not present in the graph " ); return ; }
  • 9. for ( i = u;i <= n – 1;i++ ) for ( j = 1;j <= n;j++ ) { adj[ j ][ i ] = adj[ j ][ i + 1 ]; adj[ i ][ j ] = adj[ i + 1 ][ j ]; } n–; /*Decrease the number of nodes in the graph */ } /*End of delete_node*/ insert_edge( char u, char v ) { if ( u > n ) { printf( "Source node does not exist " ); return ; } if ( v > n ) { printf( "Destination node does not exist " ); return ; } adj[ u ][ v ] = 1; } /*End of insert_edge()*/ del_edge( char u, char v ) { if ( u > n || v > n || adj[ u ][ v ] == 0 ) { printf( "This edge does not exist " ); return ; } adj[ u ][ v ] = 0; } /*End of del_edge()*/