# EmployeeManagementSystem #define _CRT_SECURE_NO_WARNINGS 1 #include #include using namespace std; void InitEmployeeSys(SNodeList& S) { //初始化函数,要求创建一个带有要求创建一个有头节点的链表, S = new StaffNode; // 分配头节点内存 if (S == nullptr) { cout << "内存分配失败!" << endl; exit(ERROR); // 如果内存分配失败,则退出程序 } S->next = nullptr; // 头节点的Next指针初始化为nullptr } void CreateEmployeeSys(SNodeList& S) { //输入一个职工记录 StaffNode* new_node = new StaffNode; if (new_node == nullptr) { cout << "内存分配失败!" << endl; exit(ERROR); // 如果内存分配失败,则退出程序 } // 输入职工信息 cout << "请输入职工姓名:"; cin >> new_node->Name; cout << "请输入职工工号:"; cin >> new_node->employeeNo; cout << "请输入职工部门:"; cin >> new_node->departmentNum; cout << "请输入职工工资:"; cin >> new_node->wages; // 将新节点添加到链表头部 new_node->next = S->next; S->next = new_node; } void PrintEmployee(SNodeList& S) { //输出所有职工信息 StaffNode* current = S->next; // 从头节点的下一个节点开始遍历 while (current != nullptr) { cout << "员工编号: " << current->employeeNo << endl; cout << "姓名: " << current->Name << endl; cout << "部门编号: " << current->departmentNum << endl; cout << "工资: " << current->wages << endl; cout << endl; current = current->next; // 移动到下一个节点 } } Status StatisticsEmployee(SNodeList& S) { //统计人数,将结果返回 if (S == nullptr) { return 0; // 如果链表为空,返回0 } int count = 0; StaffNode* current = S->next; // 从头节点的下一个节点开始计数 while (current != nullptr) { count++; current = current->next; // 移动到下一个节点 } return count; // 返回职工总数 } void SortEmpolyee(SNodeList& S) { //按照职工号、部门号和工资对所有职工排序 //冒泡排序 int judge = 0, num=StatisticsEmployee(S); printf("请选择排序方式:职工号( 1 ) || 部门号( 2 ) || 工资( 3 )\n"); while (getchar() != '\n') ; scanf("%d", &judge); if (judge == 1) { for (int i = 0; i < num-1; i++) { SNodeList p = S; for (int j = 0; j < num-1; j++) { if ((p->next->employeeNo)>(p->next->next->employeeNo)) { SNodeList q = p->next; p->next = q->next; q->next = p->next->next; p->next->next = q; } p = p->next; } } } if (judge == 2) { for (int i = 0; i < num - 1; i++) { SNodeList p = S; for (int j = 0; j < num - 1; j++) { if ((p->next->departmentNum) > (p->next->next->departmentNum)) { SNodeList q = p->next; p->next = q->next; q->next = p->next->next; p->next->next = q; } p = p->next; } } } if (judge == 3) { for (int i = 0; i < num - 1; i++) { SNodeList p = S; for (int j = 0; j < num - 1; j++) { if ((p->next->wages) > (p->next->next->wages)) { SNodeList q = p->next; p->next = q->next; q->next = p->next->next; p->next->next = q; } p = p->next; } } } } void DeleteEmployee(SNodeList& S, int employeeNum) { SNodeList current = S; while (current->next != nullptr) { if (current->next->employeeNo == employeeNum) { SNodeList temp = current->next; current->next = current->next->next; delete temp; return; } current = current->next; } //按职工号删除 } void SearchEmplyee(SNodeList& S, int employeeNum) { //按职工号查找 SNodeList p = NULL; p = S->next; int count = 1; while (p && p->employeeNo != employeeNum) { p = p->next; count++; } if (p) { printf("所找职工在第%d个位置\n", count); return; } else { printf("未找到该职员\n"); return; } }