二叉树应用程序 - 存储日期

发布于 2024-10-03 21:03:20 字数 123 浏览 0 评论 0原文

我正在开发一个简单的应用程序,规范要求必须使用二叉搜索树以 DD/MM/YYYY 格式存储日期。问题是,我很难想象结构以及节点的组织方式。

很抱歉说得含糊不清,但我能得到一些指示吗?

感谢您抽出时间!

I'm working on a simple app and the specs mandate that a binary search tree must be used for storing dates in DD/MM/YYYY format. Question is, I'm having a hard time visualizing the structure and how nodes shall be organized.

Sorry for being vague, but can I get some pointers?

Thanks for your time!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这个俗人 2024-10-10 21:03:20

基本上需要的是您创建一个比较器函数来确定一个日期相对于另一个日期是否早于或晚于(或等于)。您可以使用此函数来确定在何处放置新节点和/或它是否已存在于树中。其余的将像普通的二叉树一样工作,例如保存整数。

例如,您可以将较早的日期作为左子项,将较晚的日期作为右子项。

Basically what is required is that you make a comparator function which determines if a date is earlier or later (or equal) respective to another. You'd use this function to determine where to place a new node and/or if it already exists in the tree. The rest would work like a regular binary tree holding, say, Integers.

For example, you can put earlier dates as left children and later dates as right children.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文