使用单链表形式创建一个图书管理系统 使用python语言编程
时间: 2023-05-20 15:02:32 浏览: 115
好的,我可以回答这个问题。以下是使用Python语言创建图书管理系统的单链表代码示例:
```python
class Book:
def __init__(self, title, author, isbn):
self.title = title
self.author = author
self.isbn = isbn
self.next = None
class Library:
def __init__(self):
self.head = None
def add_book(self, title, author, isbn):
new_book = Book(title, author, isbn)
if self.head is None:
self.head = new_book
else:
current = self.head
while current.next is not None:
current = current.next
current.next = new_book
def remove_book(self, isbn):
current = self.head
previous = None
while current is not None:
if current.isbn == isbn:
if previous is None:
self.head = current.next
else:
previous.next = current.next
return True
previous = current
current = current.next
return False
def display_books(self):
current = self.head
while current is not None:
print(f"Title: {current.title}, Author: {current.author}, ISBN: {current.isbn}")
current = current.next
```
这是一个简单的图书管理系统,使用单链表来存储图书信息。可以使用`add_book`方法添加新书,使用`remove_book`方法删除书籍,使用`display_books`方法显示所有书籍的信息。
阅读全文