c++无穷大整数的设参

来源:百度知道 编辑:UC知道 时间:2024/06/08 06:38:03
#include "stdafx.h"
#include <iostream>
using namespace std;
template <class T,int size=100>
class CGraph{
struct EdgeNode{//节点;
int i,w; //头结点,权值;
EdgeNode*next;
EdgeNode(int n=0,int v=MAX_INT):next(0),i(n),w(v){}
};
struct VexNode{
T data;
EdgeNode*firstArc;
VexNode():firstArc(0){}
}VexSet[size+1];
int vn;
public:
CGraph(int n):vn(n){
int i;
cout<<"请输入"<<vn<<"个顶点数据:\n";
for(i=1;i<=vn;i++)
cin>>VexSet[i].data;
}
bool AddEdge(int i,int j,int w){
if(i==j || i<1 || j<1 || i>vn || j>vn)
return false;
EdgeNode*p=VexSet[i].firstArc;
if(p==0)VexSet[i].firstArc=new EdgeNode(j,w);
else{
while(p->next)p=p->next;
p->next=new EdgeNode(j,w);
}
return true;
}
};
中MAX_INT

把头文件打开看看,就知道MAX_INT在iostream中式已经定义好的,其实这个头文件中好多东西都定义好了,比如比大小。

学习时编写这些东西是为了练习,不是因为iostream里没有。

一楼...无语...你把iostream.h打开看的话会发现连比大小都没有定义过

头文件里面有定义

你就算把MAX_INT换成ABC都能通过, 正确的宏应该是INT_MAX, 并且是在
limits.h中定义的 而不是在iostream.h