员工管理系统数据结构线性表
时间: 2023-12-08 21:05:38 浏览: 124
员工管理系统数据结构可以使用线性表来实现。线性表是一种数据结构,它是由n个数据元素组成的有限序列。线性表中的每个元素都有一个前驱和一个后继,除了第一个元素没有前驱,最后一个元素没有后继。线性表可以用顺序存储结构或链式存储结构来实现。
在员工管理系统中,可以使用链式存储结构来实现线性表。每个节点表示一个员工的信息,包括姓名、办公室电话、手机号、电子邮箱等。每个节点还包括一个指向下一个节点的指针。整个链表的头节点指向第一个节点,最后一个节点的指针为空。
以下是一个简单的员工管理系统数据结构线性表的Python代码示例:
```python
class Employee:
def __init__(self, name, office_phone, mobile_phone, email):
self.name = name
self.office_phone = office_phone
self.mobile_phone = mobile_phone
self.email = email
self.next = None
class EmployeeList:
def __init__(self):
self.head = None
def add_employee(self, name, office_phone, mobile_phone, email):
new_employee = Employee(name, office_phone, mobile_phone, email)
if self.head is None:
self.head = new_employee
else:
current_employee = self.head
while current_employee.next is not None:
current_employee = current_employee.next
current_employee.next = new_employee
def find_employee(self, name):
current_employee = self.head
while current_employee is not None:
if current_employee.name == name:
return current_employee
current_employee = current_employee.next
return None
def remove_employee(self, name):
current_employee = self.head
previous_employee = None
while current_employee is not None:
if current_employee.name == name:
if previous_employee is None:
self.head = current_employee.next
else:
previous_employee.next = current_employee.next
return True
previous_employee = current_employee
current_employee = current_employee.next
return False
def print_list(self):
current_employee = self.head
while current_employee is not None:
print("Name:", current_employee.name)
print("Office Phone:", current_employee.office_phone)
print("Mobile Phone:", current_employee.mobile_phone)
print("Email:", current_employee.email)
current_employee = current_employee.next
```
阅读全文