[C++] 不新不好的前向星类

没啥大用,主要是想写练练手,而且还没写完

class ForwardStar{
	private:
		struct edge{
			char id;
			int next;
			int to;
			int weight;
		};
		vector<edge> e;
		vector<int> first;
	public:
		void clear(){
			e.clear();
			first.clear();
			edge Lr;
			e.push_back(Lr);
			first.push_back(0);
		}
		void Point_resize(int size){
			first.resize(size+1);
		}
		void clear(int size){
			clear();
			Point_resize(size);
		}
		void Add_edge(int start,int end){
			edge Lr;
			Lr.next=first[start];
			Lr.to=end;
			Lr.weight=0;
			Lr.id='0';
			e.push_back(Lr);
			first[start]=e.size()-1;
		}
		void Add_edge(int start,int end,int weight){
			edge Lr;
			Lr.next=first[start];
			Lr.to=end;
			Lr.weight=weight;
			Lr.id='0';
			e.push_back(Lr);
			first[start]=e.size()-1;
		}
		void Add_edge(int start,int end,int weight,char id){
			edge Lr;
			Lr.next=first[start];
			Lr.to=end;
			Lr.weight=weight;
			Lr.id=id;
			e.push_back(Lr);
			first[start]=e.size()-1;
		}
		void PartPrint_edgeid(int start){
			for(int i=first[start];i!=0;i=e[i].next){
				cout<<e[i].id<<endl;
			}
		}
		void Print_edgeid(){
			for(int i=first.size()-1;i>=1;--i){
				PartPrint_edgeid(i);
			}
		}
		void PartPrint_edge(int start){
			for(int i=first[start];i!=0;i=e[i].next){
				cout<<i<<" : from "<<start<<" to "<<e[i].to<<" with the weight of "<<e[i].weight<<endl;
			}
		}
		void Print_edge(){
			for(int i=first.size()-1;i>=1;--i){
				PartPrint_edge(i);
			}
		}
		void Print(int id){
			cout<<id<<" : "<<"to "<<e[id].to<<" with the weight of "<<e[id].weight<<endl;
		}
		int Find(int start,int end){
			for(int i=first[start];i!=0;i=e[i].next){
				if(e[i].to==end){
					return i;
				}
			}
			return -1;
		}
		void Find_Print(int start,int end){
			int x=Find(start,end);
			if(x>0){
				Print(x);
			}
			else{
				cout<<"Not Found."<<endl;
			}
		}
		void Sec_EulerianPath(){
			
		}
		void Sec_EulerianCircuit(){
			
		}
		void Sec_DFS(){
			
		}
		void Sec_BFS(){
			
		}
		void Srt_Floyed(){
			
		}
		void Srt_Dijkstra(){
			
		}
		void Srt_BellmanFold(){
			
		}
		void Srt_SPFA(){
			
		}
};
posted @   HaneDaniko  阅读(15)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
点击右上角即可分享
微信分享提示