第11讲
第一题
编写函数deln,具有删除链表中第n个结点的功能。再编写主函数,按输入顺序建立不带头结点的职工信息单链表,然后调用del函数删除某个职工的信息,并输出删除后的职工信息表中的职工信息。假设链表结构如下:
struct staff
{
char num[6]; //职工工号
char name[20]; //职工姓名
double wage; //职工工资
};
代码片
.
//
#include <iostream>
using namespace std;
struct staff
{
char num[6]; //职工工号
char name[20]; //职工姓名
double wage; //职工工资
staff *next;
};
staff * deIn(staff *head,int n)
{
int i = 1;
staff *s;
s = new staff;
s = head;
if (n > 1)
{
while (i != n - 1)
{
s = s->next;
i++;
}
s->next = s->next->next;
}
else head = head->next;
return head;
}
int main()
{
int n;
cout << "输入职工数量";
cin >> n;
cout << "输入职工姓名、工号、工资";
staff *p=NULL,