Write a member function for class Graph
Write a member function for class Graph
项目类别:计算机

Hello, dear friend, you can consult us at any time if you have any questions, add  WeChat:  zz-x2580




Question 1 (5 pt.)

Write a member function for class Graph that removes one vertex of the graph. The function should have the following prototype:

void Graph::DeleteVertex(int u);


Notice that this is a rather complex operation that should run the following actions:

• Delete all outgoing edges for u.

• Delete all incoming edges for u.

• Check the target vertex for all edges, and rename it (decrement it by 1) if it has a higher index than the vertex being removed.

• Remove entry u from the vertex array and decrement the number of vertexes.

 

Write a main program that creates a graph, prints it, removes an intermediate vertex (i.e., not the first and not the last) with both incoming and outgoing edges, and prints the resulting graph.

 

a) (4 pt.) Upload your code in a file named q1.zip. This file should contain all the code needed to compile an run the project. The program should compile and run without errors on the CoE Linux machines.

 

b) (1 pt.) What is the cost of this operation? Justify your answer.


Question 2 (5 pt.)

Write a member function for class

that returns a new dynamically allocated

object


containing the breadth-first tree of the current graph (this) given a source vertex s. You can assume that all vertexes in the graph are reachable from s. The prototype of the function should be the following:

Graph *Graph::getBFT(int s);


Write a main program that calls this function for the following graph:

 

The main program should then print the BFT by invoking function object.

on the returned


 

 

a) (4 pt.) Upload your code in a file named q2.zip. This file should contain all the code needed to compile an run the project. The program should compile and run without errors on the CoE Linux machines.

留学ICU™️ 留学生辅助指导品牌
在线客服 7*24 全天为您提供咨询服务
咨询电话(全球): +86 17530857517
客服QQ:2405269519
微信咨询:zz-x2580
关于我们
微信订阅号
© 2012-2021 ABC网站 站点地图:Google Sitemap | 服务条款 | 隐私政策
提示:ABC网站所开展服务及提供的文稿基于客户所提供资料,客户可用于研究目的等方面,本机构不鼓励、不提倡任何学术欺诈行为。