c - 如何将路线存储在链表中
问题描述
我想从文本(stdin)制作坐标路线,其中输入将是未确定数量的坐标,例如
[0,1]
[1,1]
[1,2]
.
.
.
所以我想制作一个while循环来扫描坐标并将其添加到链表中,直到它通过所有坐标。唯一的问题是我不知道从哪里开始这样做,因为我想不出如何用 x 和 y 坐标制作链表。任何能让我走上正轨的帮助都将不胜感激,干杯。
解决方案
虽然大多数链接列表的教程示例仅使用一个“有效负载”成员:
struct Node {
int value;
struct Node* next;
}
没有什么能阻止您添加更多内容:
struct Node {
int x;
int y;
struct Node* next;
}
您可能还希望对有效负载成员进行分组,以使它们与列表基础结构分开:
struct Node {
struct {
int x;
int y;
} coord;
struct Node* next;
}
推荐阅读
- kotlin - Dagger 2:从组件中的子组件暴露对象
- php - OpenCart - 无法在 MVC 之间传递数据
- xml - 如何将一个字符串中的 2 个 xml 元素与 XSLT 结合起来?
- vb.net - 从 Vb.net 服务获取其他应用程序的焦点
- spring-boot - 当我们在使用带有微服务的springboot时出现错误时如何隐藏嵌入式tomcat版本?
- python - 对于给定列中的每个不同值,计算另一列中的空值和非空值
- ios - 无法动态更新 Localizable.strings 文件
- python - 模块安装在解释器中,但在 PyCharm 的终端中无法识别
- assembly - 组装说明数据库?
- php - Wordpress 在另一个中包含模板