数据结构大作业(含源代码)
}
}
clrscr();
printf("all done!\n");
getch();
return(h);
数据结构大作业
} employee *SortByWages(employee *head) {
employee *p,*q,*s,*h,*temp; temp=malloc(sizeof(employee)); h=head; for(s=head->next; s!=NULL; s=s->next) {
数据结构大作业
else
{
p=head->next;
if(p!=NULL)
{
clrscr();
printf("all information of employee\n\n");
printf("employee's name
employee's number
number employee's wages\n");
/*no 为职工号,depno 为部门号,salary 为工资数*/
char name[maxsize];
/*职工姓名*/
struct node *pno,*pdepno,*psalary,*next; /*pno 为职工号指针,pdepno 为部门号
指针,psalary 为工资数指针*/
}employee;
数据结构大作业
p=s; for(q=s->next; q!=NULL; q=q->next) {
if((p->no)>(q->no)) p=q;
} if(p!=s) {
temp->no=s->no; temp->depno=s->depno; temp->salary=s->salary; strcpy(temp->name,s->name); s->no=p->no; s->depno=p->depno; s->salary=p->salary; strcpy(s->name,p->name); p->no=temp->no; p->depno=temp->depno; p->salary=temp->salary; strcpy(p->name,temp->name); } } clrscr(); printf("all done!\n"); getch(); return(h); }
{
p=s;
for(q=s->next; q!=NULL; q=q->next)
{
if((p->depno)>(q->depno))
p=q;
}
if(p!=s)
{
temp->no=s->no;
temp->depno=s->depno;
temp->salary=s->salary;
strcpy(temp->name,s->name);
显然, 结构体中的成员包括职工姓名、职工号、部门号、职工工资、以及一些指向
其它该类型结点的指针变量.
下面介绍实现第一个功能的代码:
employee *insert(employee *head) {
employee *h;
if(head==NULL) {
employee *s,*h1; h1=malloc(sizeof(employee));
s=malloc(sizeof(employee)); clrscr();
数据结构大作业
printf("please input employee's name:"); scanf("%s",s->name); printf("please input employee's number:"); scanf("%d",&s->no); printf("please input department's number:"); scanf("%d",&s->depno); printf("please input employee's wages:"); scanf("%d",&s->salary); s->pno=NULL; s->pdepno=NULL; s->psalary=NULL; s->next=NULL; h1->pno=NULL; h1->pdepno=NULL; h1->psalary=NULL; h1->next=s; h=h1; printf("all done!\n"); getch(); } if(head!=NULL) {
3 实验仪器
每人 1 台安装有 Turbo C 的普通学生电脑。
数据结构大作业
4 实验内容
利用静态链表来实现这一综合算法。
5 实验重点
掌握链表的常用操作。
6 程序功能及其实现详解
下面将详细介绍本程序的所有功能的实现方式即代码的含义, 在设计本程序时, 本人尽可能地用了质量好一点的算法, 因为本程序有以上 10 个功能, 显然应有实现相
s->no=p->no;
s->depno=p->depno;
s->salary=p->salary;
strcpy(s->name,p->name);
p->no=temp->no;
p->depno=temp->depno;
p->salary=temp->salary;
strcpy(p->name,temp->name);
p=s; for(q=s->next; q!=NULL; q=q->next) {
if((p->salary)>(q->salary)) p=q;
while(p!=NULL)
{
department's
printf("\t%s\t\t%d\t\t\t%d\t\t %d\n",p->name,p->no,p->depno,p->salary); p->next;
} } } getch(); } 本函数的功能是实现职工记录表中的所有记录,若没有任何一个记录, 则输出一个 提示语句来提醒使用者职工表为空, 若不为空则从第一号结点开始输出一直到最后一 个结点(以表格形式输出). 下面分别介绍根据职工号、部门号以及职工工资来排序的函数: employee *SortByEmployeeNumber(employee *head) { employee *p,*q,*s,*h,*temp; temp=malloc(sizeof(employee)); h=head; for(s=head->next; s!=NULL; s=s->next) {
2 程序简介
该程序的功能可以从以下十个方面来说明: 1.输入:添加一个职工记录 2.输出:输出全部职工记录 3.按职工号排序:通过职工号指针将职工记录按职工号从小到大连接起来 4.按职工号输出:沿职工号指针输出全部职工记录 5.按部门号排序:通过部门号指针将职工记录按部门号从小到大连接起来 6.按部门号输出:沿部门号指针输出全部职工记录 7.按职工工资排序:通过职工工资指针将职工记录按职工工资从小到大连接起来 8.按职工工资输出:沿职工号指针输出全部职工记录 9.全清:删除职工文件中有的全部记录 10.存储退出:将单链表中的全部结点存储到职工文件中,然后退出程序运行过程
employee *SortByDepartmentNumber(employee *head) {
数据结构大作业
employee *p,*q,*s,*h,*temp;
temp=malloc(sizeof(employee));
h=head;
for(s=head->next; s!=NULL; s=s->next)
employee *s,*p,*h1; h1=head; p=h1->next; s=malloc(sizeof(employee)); if(p->next!=NULL) {
while(p->next!=NULL) p=p->next;
数据结构大作业
clrscr(); printf("please input employee's name:"); scanf("%s",s->name); printf("please input employee's number:"); scanf("%d",&s->no); printf("please input department's number:"); scanf("%d",&s->depno); printf("please input employee's wages:"); scanf("%d",&s->salary); s->pno=NULL; s->pdepno=NULL; s->psalary=NULL; s->next=NULL; p->next=s; h=h1; printf("all done!\n"); getch(); } if(p->next==NULL) { clrscr(); printf("please input employee's name:"); scanf("%s",s->name); printf("please input employee's number:"); scanf("%d",&s->no); printf("please input department's number:"); scanf("%d",&s->depno);