借书图书馆数据结构

发布于 2024-10-17 06:50:44 字数 391 浏览 2 评论 0原文

首先,我想提一下这个问题是一个家庭作业问题。 我对实施的思考已经够久了。

我必须考虑并实现一个具有以下功能的图书馆软件:

  1. 添加/删除新订阅者。
  2. 借/还书。
  3. 以下订阅者有什么书?
  4. 哪个订户持有以下书籍?
  5. 拥有最多书籍的订阅者列表。

我想到了实现一个堆和2棵红黑树,问题是空间复杂度很高。所以我想知道我是否错过了什么。

订阅者通过 I.D 存储,书籍有代号。 一棵红黑树用于订阅者,另一棵用于借阅的图书。 该堆是最大堆,以实现最后一个要求。

除了数据结构之外,我不能使用其他任何东西。

感谢您任何见解和答案。

First off, I would like to mention the question is a homework question.
I have been pondering about the implementation for long enough.

I have to think and implement a library software that has the following functionalities:

  1. add/remove a new subscriber.
  2. borrow/return a book.
  3. what books the following subscriber have?
  4. which subscriber holds the following book?
  5. list of the subscribers with most books.

I thought of implementing a heap and 2 red black trees, the problem is that the space complexity is high. So I was wondering if I am missing something.

The subscribers are stored by I.Ds, the books have code names.
One Red Black tree is for the subscribers and the other is for the borrowed books.
The heap is a max heap, in order to implement the last requirement.

I cannot use anything else but data structures.

Thanks for any insights and answers.

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

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

发布评论

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

评论(1

家住魔仙堡 2024-10-24 06:50:45

我想你也可以使用容器,比如结构?用途:

  • 书籍的一个哈希集/哈希表:
    另外存储一个标志,用于确定该书是否被借出以及该书的借阅者。
  • 来自订户->链接的书籍列表的一个散列图,不仅存储所有订户,还存储他们借阅的书籍。

这允许您在 O(1) 中执行所有列出的任务,除了按订阅者借阅的书籍数量对订阅者进行排序之外。

I guess you can also use containers, like structs? Use:

  • One hash set/hash table for the books:
    Additionally store a flag which determines whether the book is borrowed and the subscriber it's borrowed to.
  • One hash map from subscriber->linked list of books, to store not only all the subscribers but also which books they have borrowed.

This allows you to perform all listed tasks in O(1), except sorting the subscribers by the count of the books they have borrowed.

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