| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 662 人关注过本帖
标题:[求助]代码错误……
只看楼主 加入收藏
哆啦梦
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-1-7
收藏
 问题点数:0 回复次数:0 
[求助]代码错误……

哪位大侠帮帮忙啊,我实在是找不出错误了,请大侠帮帮忙改一下,谢谢 const int MaxVertexes=20; template <class vertexType,class arcType>class Graph; template <class arcType>struct ArcNode{ friend class Graph <class vertexType,class arcType>; int adjvex; arcType weight; ArcNode<arcType>*nextarc; ArcNode(){} ArcNode (int v,arcType w):adjvex(v),weight(w),nextarc(NULL){} }; template <class arcType,class vertexType>struct VertexNode{ friend class Graph<class vertexType,class arcType>; vertexType data; ArcNode<arcType > *firstarc; }; template <class arcType,class vertexType>class Graph{ private: VertexNode <arcType,vertexType >*VertexTable; int CurrentNumVertexes; int CurrentNumArcs; int GetVertexPos(const vertexType &v); public: Graph():CurrentNumVertexes(0),CurrentNumArcs(0){} Graph(vertexType v[],int num=MaxVertexes); ~Graph(); int IsEmpty()const {return CurrentNumVertexes==0;} int NumberOfVertexes(){return CurrentNumVertexes;} int NumberOfArcs(){return CurrentNumArcs;} vertexType GetValue(int v); arcType GetWeight (int v1,int v2); int GetFirstNeighbor(int v); int GetNextNeighbor(int v1,int v2); int InsertVertex(vertexType &v); int InsertArc(int v1,int v2,arcType w); void DeleteVertex(int v); void DeleteArc(int v1,int v2); };

template <class vertexType,class arcType>int Graph<vertexType,arcType>::GetVertexPos(const vertexType &v){ for (int i=0;i<CurrentNumVertex;i++) if (VertexesTable[i].data==v)return i; return-1; }

template <class vertexType,class arcType>Graph<vertexType,arcType>::Graph(vertexType v[],int num=MaxVertexes): CurrentNumVertexes(0),CurrentNumArcs(0){ int e,t,h; vertexType tail, head; arcType w; VertexesTable=new VertexNode <arcType ,vertexType>[MaxVertexes]; for (int i=0;i<num;i++) InsertVertex(v[i]); cin>>e; for (int i=0;i<e;i++){ cin>>tail>>head>>w; if ((t=GetVertexPos(tail))==-1) cout<<"输入的顶点不存在"; else if ((h=GetVertexPos(head))==-1) cout<<"输入的顶点不存在"; else InsertArc(t,h,w); } }

template <class vertexType,class arcType> Graph <vertexType,arcType>::~Graph(){ for(int i=0;i<=CurrentNumVertexes;i++){ ArcNode <ArcType>*p=VertexesTable[i].firstarc; while(p!=NULL){ VertexesTable[i].firstarc=p->nextarc; delete p; p=VertexesTable[i].firstarc;} } delete [] VertexesTable; }

template <class vertexType,class arcType> vertexType Graph<vertexType,arcType>::GetValue(int v){ if(v>=0 && v<CurrentNumVertexes) return VertexesTable[v].data; return NULL; }

template <class vertexType,class arcType> arcType Graph<vertexType,arcType>::GetWeight(int v1,int v2){ if(v1>=0 && v1<CurrentNumVertexes && v2>=0 && v2<CurrentNumVertexes){ ArcNode <ArcType> *p=VertexesTable[v1].firstarc; while(p!=NULL){ if(p->adjvex==v2) return p->weight; else p=p->nextarc; } } return NULL; }

template <class vertexType,class arcType> int Graph <vertexType,arcType>::GetFirstNeighbor(int v){ if(v>=0 && v<CurrentNumVertexes){ ArcNode <ArcType> * p=VertexesTable[v].firstarc; if(p!=NULL) return p->adjvex; } return -1; }

template <class vertexType,class arcType> int Graph <vertexType,arcType>::GetFirstNeighbor(int v1,int v2){ if(v1>=0 && v1<CurrentNumVertexes){ ArcNode<ArcType> * p=VertexesTable[v1].firstarc; while(p!=NULL){ if(p->adjvex==v2 && p->nextarc!=NULL) return p->nextarc->adjvex; else p=p->nextarc; } } return -1; }

template <class vertexType,class arcType> int Graph <vertexType,arcType>::InsertVertex(vertexType & v){ if(CurrentNumVertexes <MaxVertexes){ VertexesTable[CurrentNumVertexes].data=v; VertexesTable[CurrentNumVertexes].firstarc=NULL; CurrentNumVertexes++; return 1; } return 0; }

搜索更多相关主题的帖子: 代码 
2005-01-08 17:31
快速回复:[求助]代码错误……
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016955 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved