这是我第一次使用sml。
我不明白这种语法有什么问题:
fun merge (l1 : int list , l2 : int list) : int list =
if ([] , l2) then l2
else if (l1 , []) then l1
else (x :: xs , y :: ys)
if x < y then x :: (merge (xs , l2))
else y :: (merge (l1 , ys)));
请帮忙
答案 0 :(得分:1)
问题是/**
* Definition for a point.
* struct Point {
* int x;
* int y;
* Point() : x(0), y(0) {}
* Point(int a, int b) : x(a), y(b) {}
* };
*/
class Solution {
private:
Point ori;
class Comparator {
public:
// calculate the euclidean distance between p and ori
int distance(Point p) {
return pow(p.x-ori.x, 2) + pow(p.y-ori.y, 2);
}
// overload the comparator (), the nearest point to
// origin comes to the first
bool operator() (Point l, Point r) {
if (distance(l) > distance(r)) {
return true;
}
}
};
public:
/*
* @param points: a list of points
* @param origin: a point
*/
void mainFunc(vector<Point> points, Point origin) {
ori = origin;
priority_queue<Point, vector<Point>, Comparator> pq;
for (int i = 0; i < points.size(); i++) {
pq.push(points[i]);
}
}
};
/ if
/ then
语法不用于模式匹配。 (你已经融合了两种不相关的语法。)
因此,例如,else
不起作用,因为if ([] , l2)
表达式中的条件需要if
类型,而bool
则不需要。{/ p >
相反,你想写:
([], l2)