- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
// Construct an array of length MAX_POINTS.
// Populate the array with given points and initialize the number points being handled.
// Print the given points for the user.
struct Point points[MAX_POINTS];
int numPoints = readPoints(points);
printf("Set of points: \n");
displayPoints(points, numPoints);
// Construct an array to represent the hull with max possible points (numPoints).
struct Point hull[numPoints];
struct Point pointOnHull = leftmostPoint(points, numPoints);
struct Point endPoint;
int e = 0;
// Perform Jarvis March.
do {
hull[e] = pointOnHull;
endPoint = points[0];
for ( int i = 1; i < numPoints; i++ )
if ( (endPoint == pointOnHull) || (ccw(hull[e], endPoint, points[i]) > 0) )
endPoint = points[i];
++e;
} while ( endPoint != hull[0] ); // we've looped back to the beginning.
// Print the mapped hull points.
printf("Convex hull: \n");
displayPoints(hull, numPoints);
这是我用于解决凸包问题的 Jarvis March(礼品包装)程序的代码。 GCC 在我的两个结构点比较 (endPoint == pointOnHull
和 endPoint != hull[0])
上都出现了错误。我是 C 语言的新手,这是我为玩弄这门语言所做的首批项目之一。谁能帮我看看我哪里搞砸了?
具体错误:
jarvis.c:31:19: error: invalid operands to binary == (have 'struct Point' and 'struct Point')
jarvis.c:34:21: error: invalid operands to binary != (have 'struct Point' and 'struct Point')
最佳答案
C
中没有结构比较运算符。您必须定义自己的比较函数并使用它来代替 ==
。尝试这样的事情:
bool equalPoints(const struct Point p1, const struct Point p2) {
return (p1.x == p2.x) && (p1.y == p2.y);
}
if (equalPoints(endPoint, pointOnHull)) { /* then code here */ }
或者如果您的结构更复杂(尽管情况可能并非如此):
bool equalPoints(const struct Point *p1, const struct Point *p2) {
/*
* In case your structure is more complex here goes
* more complex comparison code
*/
return (p1->x == p2->x) && (p1->y == p2->y);
}
if (equalPoints(&endPoint, &pointOnHull) { /* then code here */ }
后者不会复制整个 Point
结构以将其传递给 equalPoints
,而是传递指针(引用类型)。 const
很重要,因为它不会让您在只想比较点时不小心修改点。
关于c - 我在某个时候失去了我的对象的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19213457/
我在我的项目(Ubuntu 18.04.2 LTS)中使用了 celery 4.4.0 版本。当我提出异常('功能中的功能太少无法分类')时, celery 项目失去了 worker ,我得到了这样的
我在这样的更新面板中有一个 GridView :
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 这个问题似乎不是关于 a specific programming problem,
当我尝试使用 jquery 的 html() 将 HTML 附加到另一个元素时。我失去了 ng-click 的能力。这是我的代码的粗略描述。例如我有一个名为 testController 的 Cont
我正在将 python 连接到 mySqL 数据库,并从 android 发送两个 Double 值以存储在 Mysql 中,然后我收到此错误 enter code here Exception i
无法理解为什么这个简单的事情没有反应性。看起来我错过了一些 Vue 的基础。 {{connection_status}} export default {
我不明白出了什么问题,在我的设备上应用程序运行良好,但有时在日志中(应用程序用户、 session 、崩溃......通过某些服务跟踪)我看到应用程序崩溃(NullPointerException),
我正在处理一个我有点困惑的问题。问题是假设您是二战期间英国空军的一名将军。您还剩下 100 架飞机来保卫英国。在您执行的每个任务中,每架飞机都有 50% 的几率被德国高射炮击落,因此每次执行任务您都会
我相信我的问题与以下问题非常相似 Spring security 'remember me' cookie not avaiable in first request . 基本上,我有一组用于公司内部
似乎 Bootstrap 下拉按钮在单击后仍保持焦点。 我的用例与此不兼容, 用户应该在单击按钮后按“SPACE”键,为了触发与按钮无关的东西。 问题是按钮保持焦点状态,因此按空格键 激活按钮。 我希
我有一个 MKMapView,其中有很多从解析器 xml 定义的注释引脚;那是我的代码: -(IBAction)LoadAnnotation:(id)sender { RXML element
我有一个 HTML 表格,用户可以在其中输入他的待机开始时间和待机结束时间,该时间计算总时数,并基于此计算获得的补偿时数。这一切都有效。 现在,它所做的是,每当用户输入开始和结束时间时,用户必须将焦点
Windows 系统更新后,Eclipse 不再了解 Android 的任何信息...我如何恢复对 Android 的支持?我尝试重新安装 SDK,但没有成功... 太奇怪了。我注意到项目模板丢失了,
我正在发送 SOAP 请求来更新某些实体。当我创建(而不是更新)几乎相同的东西时,一切正常。我跟踪了客户端和传输的日志记录,最后它给了我一个线索。它看起来像这样: DEBUG:suds.client:
这个问题在这里已经有了答案: TypeError: Cannot read property 'setState' of undefined (3 个答案) How to access the co
我使用 PostgreSQL 和 repmgrd 创建了一个 Docker 镜像,所有这些镜像都是使用 supervisor 启动的。 我现在的问题是,当它启动时,由 supervisor 生成的 r
新的 iOS 开发者为 iPhone 编写第一个委托(delegate)应用程序。 模态调用的父 View Controller 有六个 subview Controller ,它们使用父 View
我目前正在 MVC4 中创建一些用户配置文件编辑表单,并且为了测试,我将 UserId 属性呈现为表单上的只读文本框,如下所示: @Html.LabelFor(model => model.
我是一名优秀的程序员,十分优秀!