⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adjtwgraph.h

📁 数据结构头文件源代码
💻 H
字号:
struct Edge   //
{
	int dest;]
		DistT weight;
	Edge *next;

	Edge(){}
	Edge(int d,DistT w):Dest(d),weight(w),next(NULL){}
};
struct item
{
	VerT data;
	Edge * adj;
};

class AdjTwGraph
{
private:
	item Vertices[MaxVertices];
	int numVertices;
	int numOfEdges;
public:
	AdjTWGraph(void);
	~AdjTWGraph(void);

	int GraphEmpty()const
	{return numVertices==0;}
	int NumOfVertices(void)
	{return numVertices;}
	int NumOfEdges(void)
	{return numOfEdgds;}
	VerT GetValue(const int i);
	int GetWeight(const int v1,const int v2);

	int GetFirstNeighbor(const int v);
	void DeleteEdge(const int v1,const int v2);

	//
	void DepthFirstSearch(const int v,int visited[],
		void visit(VerT item));
	//
	void DepthFirstSearch(void visit(VerT item));
	//
	void BroadFirstSearch(const int v,int visited[],
		void visit(VerT item));
	//
	//void BroadFirstSearch(void visit(VerT item));

	/*1. 构造函数和析构函数*/
	AdjTWGraph::AdjTWGraph(void)
	{
		for (int i=0;i<MaxVertices;i++)Vertices[i].adj=NULL;
		numVertices=0;
		numOfEdges=0;
	}

	AdjTWGraph::~AdjTWGraph(void)
		//
	{
		for(int i=0;i<numVertices;i++)
		{
			Edge *p=Vertices[i].adj,*q;
			while(p!=NULL)
			{
				q=p->next;
				delete p;
				p=q;
			}
		}
	}
	/* 2.简单成员函数的实现 */
	VerT AdjTWGraph::GetValue(const int i)
	{
		if(i<0||i>numVertices)
		{
			cout<<""endl;
			exit(0);
		}
		return Vertices[i].data;
	}

	int AdjTWGraph::GetWeight(const int v1,const int v2)
	{
		if(v)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -