数据结构课程设计之员工通讯录

本文介绍了使用C语言进行数据结构课程设计,通过创建单链表实现员工通讯录的功能,包括结构体定义、指针节点操作,以及增删查改等操作。
摘要由CSDN通过智能技术生成
0x00 主要思想

员工通讯录的实现其实就是单链表的简单应用,只要预先定义一个存放通讯录数据信息的结构体,以及相关的指针结点等,然后就是单链表的以希望简单应用用来实现创建、插入、查找、删除、以及其他的相关功能即可。


0x01 程序源码

//单位员工通讯录管理系统
#include<string.h>
#include<ctype.h>
#include<malloc.h>
#include<limits.h>
#include<stdio.h>
#include<stdlib.h>
#include<io.h>
#include<math.h>
#include<process.h>
#include<iostream>
using namespace std;
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0


typedef int Status;
typedef int ElemType;

typedef struct
{
char name[25];
char num[5];
char call[15];
char phone[15];
char mail[25];
}DataType;
typedef struct Node
{

DataType data;
struct Node *next;
struct Node *t;
}Node,*LinkList;
// 构造一个空链表并向其中插入数据
int Createlinklist(LinkList &L)
{
L = (LinkList)malloc(sizeof(Node));
int n;
printf("请输入建立通讯录员工的人数:");
scanf_s("%d",&n);
LinkList q;
L->next = NULL;
q = L;
for (int i = 0; i < n;i++)
{
LinkList p;
p = (LinkList)malloc(sizeof(Node));

printf(" 员工编号:");
cin >> p->data.num;
printf(" 员工姓名:");
cin >> p->data.name;
printf(" 手机号码:");
cin >> p->data.call;
printf(" 办公室电话:");
cin>>p->data.phone;
printf(" 邮箱地址:");
cin>>p->data.mail;
p->next = NULL;
q->next = p;
q = p;

}
return 0;
}
//判断链表是否为空并输出p指针结点(查找的前段步骤)
LinkList LinkEmpty(LinkList &L)
{
char number[5];
printf("请输入员工编号:");
scanf_s("%s",number,5);
LinkList p = L;
if (!(p->next))
{
printf("通讯录为空,请先输入后再查询!");
return NULL;
}
else
{
while (p!=L->t)
if (strcmp(p->next->data.num, number))
p = p->next;
else
return p;
return p;
}
}
//查找出员工
int Findperson(Li
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数据结构课程设计 include "stdio.h" #include "ctype.h" #include "string.h" #include"stdlib.h" #include "malloc.h" struct list { char name[10]; char street[10]; char city[10]; char state[10]; char eip[10]; struct list *prior; struct list *next; }; void mainmenu(struct list * head); void read_file(struct list * head); void read_file(); void px_menu(struct list * head); void px_name(struct list * head); void px_street(struct list * head); void px_city(struct list * head); void px_state(struct list * head); void px_eip(struct list * head); void delete_menu(struct list * head); void delete_name(struct list * head); void search_menu(struct list * head); void search_name(struct list * head); void search_street(struct list * head); void search_city(struct list * head); void search_state(struct list * head); void search_eip(struct list * head); void add_new(struct list * head); void prin_list(struct list * head); void write_file(struct list * head); int flag=0; int flag1=0;//删除为空标志位 void main() { struct list *head; read_file(); mainmenu(head); return; } /**************************************************** 主菜单 ****************************************************/ void mainmenu(struct list * head) { char tmp; system("cls"); printf("输入要进行的操作:\n"); printf("\t '1'-----------------------添加记录\n"); printf("\t '2'-----------------------排序记录\n"); printf("\t '3'-----------------------显示记录\n"); printf("\t '4'-----------------------查找记录\n"); printf("\t '5'-----------------------删除记录\n"); printf("\t '6'---------------------------退出\n"); printf("\t '0'---------------------保存并退出\n"); printf("\n\t请选择:"); tmp=getchar(); switch(tmp) { case '1':add_new(head);break; case '2':px_menu(head);break; case '3':prin_list(head);break; case '4':search_menu(head);break; case '5':delete_menu(head);break; case '6':exit(0);break; case '0':write_file(head);break; default :{printf("错误操作返回主菜单");mainmenu(head);} } } /**************************************** 双链表建立以及文件读取 ****************************************/ //void read_file(struct list * head) void read_file() { int i; struct list *p1,*p2; struct list *head; FILE *fp; fp=fopen("list.txt","a"); fclose(fp); if ((fp = fopen ( "list.txt" , "rt" ) ) == NULL ) { printf("打开文件失败\n"); exit(0) ; } rewind(fp);//将文件指针重新指向流的开头 fseek(fp,0,2);//重定位流上的文件指针 if ((ftell(fp)==0))//返回当前文件指针 { printf("没有记录:\n"); head=p1=p2=(struct list *)malloc(sizeof(struct list)); head->name[10]='\0'; head->street[10]='\0'; head->city[10]='\0'; head->state[10]='\0'; head->eip[10]='\0'; head->next=head; head->prior=head; flag=1; } else { rewind(fp); head=p1=p2=(struct list *)malloc(sizeof(struct list)); head->next=head; head->prior=head; if(fread(p1,sizeof(struct list),1,fp)!=1)//从流中读数据 { p2->next=p1; p1->next=head; head->prior=p1; p1->prior=p2; p2=p1; } else { for (i=0;;i++) { p2->next=p1; p1->next=head; head->prior=p1; p1->prior=p2; p2=p1; if (feof ( fp ))//检测流上的文件结束符用 { p1->next=head; head->prior=p1; printf("记录读入完成\n"); break; } else { p1=(struct list *)malloc(sizeof(struct list)); p1->name[10]='\0'; p1->street[10]='\0'; p1->city[10]='\0'; p1->state[10]='\0'; p1->eip[10]='\0'; if(fread(p1,sizeof(struct list),1,fp)!=1) { break; } } } } } printf("记录读入完成\n"); fclose ( fp ) ; printf("按任意键进入主菜单\n"); getchar(); mainmenu(head); return; } /**************************************** 增添 ****************************************/ void add_new(struct list * head) { int k=0; int n; char tmp1,tmp2; struct list *p; struct list *p1,*p2; p1=(struct list *)malloc(sizeof(struct list)); p1->name[10]='\0'; p1->street[10]='\0'; p1->city[10]='\0'; p1->state[10]='\0'; p1->eip[10]='\0'; printf("请输入所要添加的名字:\n"); scanf("%s",p1->name); printf("请输入所要添加的街道:\n");

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值