I am very new to programming and currently undertaking a programming degree, I’m required to create a simple library management system using both a linked list and a stack in c++ I can probably make the whole system using just a linked list and a class that stores the book details but the TA demands that I use both. How do I use both in this situation?
>Solution :
I assume, by library management system, you mean a simple program to manage standard functions to handle an actual library (like borrowing books). If you need to develop a system to handle literature in an article (like BibTeX or EndNote), please comment :).
Okay so what do we need to manage a library? The most basic functions are imho:
- search for a specific book
- see all books in a category
- borrow a book
- return a book
- see your borrowed books
For the search and the categories, a linked list is perfect. To save your borrowed books, you could use a stack, as you basically always want to show all of them and the stack is the simpler datastructure. Of course you could also just use a property of the book, if and who borrowed it and show all the books tagged as borrowed by you, when displaying your borrowed books, if you want to optimise for space, but this could be slow as you have more books in the library than in your "bag".
Another great application for the stack in this case is in the borrowing process, if you want to keep the history of who borrowed the book. you can just push the user to the stack as they are the last ones to borrow it for now.
This is just some ideas, hope it helped! 🙂