数据结构课程设计手机通讯录
时间: 2024-06-13 14:09:58 浏览: 152
手机通讯录系统安卓课程设计
5星 · 资源好评率100%
针对数据结构课程设计手机通讯录,可以采用链表存储通讯记录,具体设计如下:
1. 结点结构设计
通讯录中每个联系人的信息可以看作是一个结点,每个结点包含以下信息:
- 姓名
- 手机号码
- 电子邮箱
- 地址
- 生日
因此,结点的结构可以设计如下:
```python
class ContactNode:
def __init__(self, name, phone, email, address, birthday):
self.name = name
self.phone = phone
self.email = email
self.address = address
self.birthday = birthday
self.next = None
```
其中,next指向下一个结点,用于实现链表的存储。
2. 链表操作实现
可以定义一个ContactList类,用于实现链表的操作,包括:
- 添加联系人
- 删除联系人
- 修改联系人信息
- 查找联系人
- 显示所有联系人
具体实现可以参考以下代码:
```python
class ContactList:
def __init__(self):
self.head = None
# 添加联系人
def add_contact(self, name, phone, email, address, birthday):
new_node = ContactNode(name, phone, email, address, birthday)
if self.head is None:
self.head = new_node
else:
current = self.head
while current.next is not None:
current = current.next
current.next = new_node
# 删除联系人
def delete_contact(self, name):
if self.head is None:
return
if self.head.name == name:
self.head = self.head.next
else:
current = self.head
while current.next is not None:
if current.next.name == name:
current.next = current.next.next
return
current = current.next
# 修改联系人信息
def modify_contact(self, name, phone=None, email=None, address=None, birthday=None):
current = self.head
while current is not None:
if current.name == name:
if phone is not None:
current.phone = phone
if email is not None:
current.email = email
if address is not None:
current.address = address
if birthday is not None:
current.birthday = birthday
return
current = current.next
# 查找联系人
def search_contact(self, name):
current = self.head
while current is not None:
if current.name == name:
return current
current = current.next
return None
# 显示所有联系人
def display_all(self):
current = self.head
while current is not None:
print("Name:", current.name)
print("Phone:", current.phone)
print("Email:", current.email)
print("Address:", current.address)
print("Birthday:", current.birthday)
print("--------------------")
current = current.next
```
3. 相关问题:
阅读全文