问题及代码:
/***************************************************************************************/
*版权所有 (C)2015,SongChen
*
*文件名称:messageguanli.cpp
*文件标识:无
*内容摘要:head.h dingyi.cpp main.cpp
*其它说明:无
*当前版本:V1.0
*作者:宋晨
*完成日期:20151225
/***************************************************************************************/
头文件head.h
#ifndef HEAD_H_INCLUDED
#define HEAD_H_INCLUDED
struct employee
{
char id[20];//工号
char name[20];//姓名
char sex[20];//性别
char age[20];//年龄
char edu[20];//学历
char salary[20];//工资
char phone[30];//电话
char address[30];//地址
};
//存储结构
typedef struct LNode
{
struct employee data;
struct LNode* next;
}LNode,*Linklist;
int Initlist(Linklist *L);//初始化单链表
int CreatList(Linklist L);//头插法生成单链表
void Display(Linklist L);//显示职工信息
int SearchID(Linklist L,char id[20]);//ID查询
int SearchName(Linklist L,char name[10]);//姓名查询
void SortID(Linklist L);//编号排序
void SortName(Linklist L);//姓名排序
int Ins(Linklist L, char id[20]);//插入信息
int Alter(Linklist L,char id[20]);//更改信息
int Del(Linklist L,char id[20]);//按ID删除
#endif // HEAD_H_INCLUDED
各函数的定义 dingyi.cpp
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "head.h"
#define OK 1
#define ERROR 0
/***************************************************************************************/
*功能描述:初始化单链表
*输入参数:无
*输出参数:无
*返回值:1
*其他说明:消息字段之间用分号(;)隔离
/***************************************************************************************/
int Initlist(Linklist *L) //初始化单链表
{
(*L)=(Linklist)malloc(sizeof(LNode));
if(!(*L))
return (0);
(*L)->next=NULL;
return OK;
}
/***************************************************************************************/
*功能描述:头插法生成单链表
*输入参数:职工各项信息
*输出参数:无
*返回值:1或0
*其他说明:消息字段之间用分号(;)隔离
/***************************************************************************************/
int CreatList(Linklist L)//头插法生成单链表
{
Linklist p;
p=(Linklist)malloc(sizeof(LNode));
if(!p)
{
return (0);
}
else
{
printf("请输入员工信息\n");
printf("编号:");
scanf("%s",p->data.id);
printf("姓名:");
scanf("%s",p->data.name);
printf("性别:");
scanf("%s",p->data.sex);
printf("年龄:");
scanf("%s",p->data.age);
printf("学历:");
scanf("%s",p->data.edu);
printf("工资:");
scanf("%s",p->data.salary);
printf("电话:");
scanf("%s",p->data.phone);
printf("地址:");
scanf("%s",p->data.address);
}
p->next=L->next;
L->next=p;
return OK;
}
/***************************************************************************************/
*功能描述:显示职工信息
*输入参数:无
*输出参数:职工各项信息
*返回值:无
*其他说明:消息字段之间用分号(;)隔离
/***************************************************************************************/
void Display(Linklist L)//显示职工信息
{
Linklist p;
for(p=L->next;p;p=p->next)
{
pr