职工工资管理系统+链表
时间: 2024-03-03 19:46:06 浏览: 26
职工工资管理系统是一个用于管理职工资信息的软件系统。它可以记录和管理职工的基本信息、工资信息以及相关的统计数据。链表是一种常用的数据结构,可以用来存储和组织数据。
在职工工资管理系统中,可以使用链表来存储职工的信息。链表由一系列节点组成,每个节点包含了职工的信息以及指向下一个节点的指针。通过使用链表,可以方便地插入、删除和查找职工信息,同时也可以节省内存空间。
以下是一个简单的职工工资管理系统+链表的实现示例:
1. 定义职工结构体:
```
struct Employee {
int id; // 职工编号
string name; // 职工姓名
float salary; // 职工工资
Employee* next; // 指向下一个节点的指针
};
```
2. 创建链表并实现相关操作:
```
class EmployeeList {
private:
Employee* head; // 链表头指针
public:
EmployeeList() {
head = nullptr; // 初始化链表为空
}
// 添加职工信息
void addEmployee(int id, string name, float salary) {
Employee* newEmployee = new Employee;
newEmployee->id = id;
newEmployee->name = name;
newEmployee->salary = salary;
newEmployee->next = nullptr;
if (head == nullptr) {
head = newEmployee;
} else {
Employee* current = head;
while (current->next != nullptr) {
current = current->next;
}
current->next = newEmployee;
}
}
// 删除职工信息
void deleteEmployee(int id) {
if (head == nullptr) {
return;
}
if (head->id == id) {
Employee* temp = head;
head = head->next;
delete temp;
} else {
Employee* current = head;
while (current->next != nullptr && current->next->id != id) {
current = current->next;
}
if (current->next != nullptr) {
Employee* temp = current->next;
current->next = current->next->next;
delete temp;
}
}
}
// 查找职工信息
Employee* findEmployee(int id) {
Employee* current = head;
while (current != nullptr && current->id != id) {
current = current->next;
}
return current;
}
};
```