输入正文
#pragma once
#include<iostream>
using namespace std;
template<typename Weight>
class Edge {
private:
int a;
int b;
Weight weight;
public:
Edge(int a, int b, Weight weight) {
this->a = a;
this->b = b;
this->weight = weight;
}
Edge() {};
~Edge() {};
int v() {
return a;
}
int w() {
return w;
}
Weight wt() {
return weight;
}
int other(int x) {
assert(x == a || x == b);
return x == a ? b : a;
}
//重载输出运算符
friend ostream& operator<<(ostream &os, const Edge &e) {
os << e.a << "-" << e.b << ": " << e.weight;
return os;
}
//重载小于号
bool operator<(Edge<Weight>& e) {
return weight < e.wt();
}
bool operator<=(Edge<Weight>& e) {
return weight <= e.wt();
}
bool operator>(Edge<Weight>& e) {
return weight > e.wt();
}
bool operator>=(Edge<Weight>& e) {
return weight >= e.wt();
}
bool operator==(Edge<Weight>& e) {
return weight == e.wt();
}
};
就是不明白为什么一个类Edge,后面可以用尖括号 ,这种语法以前没见过啊