借书图书馆数据结构
首先,我想提一下这个问题是一个家庭作业问题。 我对实施的思考已经够久了。
我必须考虑并实现一个具有以下功能的图书馆软件:
- 添加/删除新订阅者。
- 借/还书。
- 以下订阅者有什么书?
- 哪个订户持有以下书籍?
- 拥有最多书籍的订阅者列表。
我想到了实现一个堆和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:
- add/remove a new subscriber.
- borrow/return a book.
- what books the following subscriber have?
- which subscriber holds the following book?
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你也可以使用容器,比如结构?用途:
另外存储一个标志,用于确定该书是否被借出以及该书的借阅者。
这允许您在 O(1) 中执行所有列出的任务,除了按订阅者借阅的书籍数量对订阅者进行排序之外。
I guess you can also use containers, like structs? Use:
Additionally store a flag which determines whether the book is borrowed and the subscriber it's borrowed to.
This allows you to perform all listed tasks in O(1), except sorting the subscribers by the count of the books they have borrowed.