#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
typedef class lnode {
public:
int no;
int depno;
int value;
string name;
class lnode* next;
}lnode, * linklist;
//初始化链表
bool initlist(linklist& L)
{
L = (lnode*)new lnode;//指向头结点
if (L == NULL)
return false;//内存不足,分配空间失败
(*L).next = NULL;//头节点为空
return true;
}
//在第i个节点插入(链表指针,节点序号,编号s,部门号de,名字n,价格v)
bool listinsert(linklist& L, int i, int s, int de, string n, int v)
{
if (i < 1)
return false;
lnode* p;//当前扫描到的节点指针
int j = 0;//p指向的是第几个节点
p = L;//指向头节点
while (p != NULL && j < i - 1)//使p指向插入节点的前一个节点
{
p = p->next;
j++;
}
if (p == NULL)
return false;
lnode* s1 = (lnode*)new lnode;
s1->no = s;
s1->name = n;
s1->depno = de;
s1->value = v;
s1->next = p->next;
p->next = s1;
return true;
}
//删除第i个节点
bool listdelete(linklist& L, int i)
{
if (i < 1)
return false;
lnode* p;//当前节点指针
int j = 0;
p = L;
while (p != NULL && j < i - 1)//使p指向i-1节点处
{
p = p->next;
j++;
}
if (p == NULL)
return false;
if (p->next == NULL)
return false;
lnode* q = p->next;
p->next = q->next;
delete q;
return true;
}
//菜单显示
void menu()
{
cout << "-------------------------------------------------------------------------" << endl;
cout << "请操作:" << endl;
cout << "1:初始化链表(从链表标号一插入)" << endl;
cout << "2:链表序号插入教职工信息" << endl;
cout << "3:删除信息" << endl;
cout << "4:显示全部信息" << endl;
cout << "5:查找" << endl;
cout << "6:排序" << endl;
cout << "7:退出" << endl;
cout << "-------------------------------------------------------------------------" << endl;
}
//下级菜单显示
void menu2()
{
cout << "-------------------------------------------------------------------------" << endl;
cout << "请操作:" << endl;
cout << "1:按链表位序查找" << endl;
cout << "2:按名字查找" << endl;
C++单链表实现教职工管理系统
于 2022-05-01 20:48:32 首次发布
#include<iostream>#include<string>#include<iomanip>using namespace std;typedef class lnode {public: int no; int depno; int value; string name; class lnode* next;}lnode, * linklist;//初始化链表bool initlist(linklist& L){.
摘要由CSDN通过智能技术生成