16:算法--图的转置

图的转置

算法性质

返回输入图的转置图

接口设计

template
class ReverseGraph
{
public:
	typename typedef DataStruct::GraphStruct::Graph InnerGraph;
	ReverseGraph(const InnerGraph& nGraph_);
	~ReverseGraph();

	InnerGraph Run();
private:
	ReverseGraph(const ReverseGraph& nGraph_) = default;
	ReverseGraph& operator=(const ReverseGraph& nGraph_) = default;

private:
	const InnerGraph& m_nGraph;
};

实现

构造

template
ReverseGraph::ReverseGraph(const InnerGraph& nGraph_)
	: m_nGraph(nGraph_)
{

}

析构

template
ReverseGraph::~ReverseGraph()
{

}

算法运行

template
typename DataStruct::GraphStruct::Graph ReverseGraph::Run()
{
	InnerGraph _nGraph;
	DataStruct::Array::DynArray _arrNodes = m_nGraph.GetNodesArray();
	for (int _i = 0; _i < _arrNodes.GetSize(); _i++)
	{
		_nGraph.AddNode(_arrNodes[_i]->GetPair());
	}

	DataStruct::Array::DynArray _arrEdges = m_nGraph.GetEdgesArray();
	for (int _i = 0; _i < _arrEdges.GetSize(); _i++)
	{
		_nGraph.AddEdge(_arrEdges[_i]->GetIdentity().Reverse());
	}

	return _nGraph;
}

关联开源项目

https://github.com/xubenhao/Algorithm

你可能感兴趣的:(2.1.数据结构与算法,图,算法,图的转置)