没有合适的资源?快使用搜索试试~ 我知道了~
数据结构课程设计(C语言版)(答案)
需积分: 31 21 下载量 30 浏览量
2015-03-31
17:21:30
上传
评论 6
收藏 181KB DOC 举报
温馨提示
试读
43页
1、某软件公司大约有30名员工,每名员工有姓名、工号、职务等属性,每年都有员工离职和入职。 把所有员工按照顺序存储结构建立一个线性表,建立离职和入职函数,当有员工离职或入职时,修改线性表,并且打印最新的员工名单。 2、约瑟夫(Josephus)环问题:编号为1,2,3,…,n的n个人按顺时针方向围坐一圈,每人持有一个密码(正整数)。一开始任选一个正整数作为报数的上限值m,从第一个人开始按顺时针方向自1开始顺序报数,报到m时停止。报m的人出列,将他的密码作为新的m值,从他在顺时针方向上的下一人开始重新从1报数,如此下去,直到所有人全部出列为止。 建立n个人的单循环链表存储结构,运行结束后,输出依次出队的人的序号。 3、某商场有一个100个车位的停车场,当车位未满时,等待的车辆可以进入并计时;当车位已满时,必须有车辆离开,等待的车辆才能进入;当车辆离开时计算停留的的时间,并且按照每小时1元收费。 汽车的输入信息格式可以是(进入/离开,车牌号,进入/离开时间),要求可以随时显示停车场内的车辆信息以及收费历史记录。 4、某银行营业厅共有6个营业窗口,设有排队系统广播叫号,该银行的业务分为公积金、银行卡、理财卡等三种。公积金业务指定1号窗口,银行卡业务指定2、3、4号窗口,理财卡业务指定5、6号窗口。但如果5、6号窗口全忙,而2、3、4号窗口有空闲时,理财卡业务也可以在空闲的2、3、4号窗口之一办理。 客户领号、业务完成可以作为输入信息,要求可以随时显示6个营业窗口的状态。
资源推荐
资源详情
资源评论
线性表
1、某软件公司大约有 30 名员工,每名员工有姓名、工号、职务等属性,每年都有员工离
职和入职。
把所有员工按照顺序存储结构建立一个线性表,建立离职和入职函数,当有员工离职
或入职时,修改线性表,并且打印最新的员工名单。
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "malloc.h"
#dene SIZE sizeof(employee)
typedef struct employee
{
char name[20] ;
int number ;
char post[20] ;
employee *next ;
}employee ;
int n ;
employee *s ;
void InitComp()
{
printf("start create:") ;
int i = 0 ;
employee *p , *q =NULL ;
while(i < n)
{
p = (employee *)malloc(SIZE) ;
printf("please enter name");
scanf_s("%s",&(p->name),20);
printf("please enter number");
scanf_s("%d",&(p->number));
printf("please enter post");
scanf_s("%s",&(p->post),20);
p->next = NULL ;
i++ ;
if(i == 1)
{
s = p ;
q = p ;
}
else{
q->next = p ;
q = q->next ;
}
}
}
void EmpInsert()
{
employee *p ,*q = s;
while(q->next!=NULL)
q = q->next ;
p = (employee *)malloc(SIZE) ;
printf("please enter name\n");
scanf_s("%s",&p->name,20);
printf("please enter number\n");
scanf_s("%d",&p->number);
printf("please enter post\n");
scanf_s("%s",&p->post,20);
q->next = p ;
p->next = NULL ;
n++ ;
}
void EmpDelete(int num)
{
employee *p=s,*q=s;
int i=0,j = 0;
while(j<n){
i=p->number;
if(i==num){
if(p==s){
s = s->next;
}
else{
q->next = p->next;
}
n--;
return ;
}
else {
q = p;
p = p->next;
j++;
}
}
printf("number not found\n") ;
}
void EmpPrint()
{
employee *p = s;
printf("the list of employees\n") ;
while(p !=NULL)
{
printf("%s\t%d\t%s\n",p->name,p->number,p->post) ;
p = p->next ;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int l ,m;
printf("create list,please enter the number of the employee\n");
scanf_s("%d",&n) ;
InitComp() ;
EmpPrint() ;
while(1)
{
printf("enter number to choose action:1 for indert ,2 for delete\n") ;
scanf_s("%d",&l) ;
switch(l)
{
case 1:
EmpInsert() ;
EmpPrint() ;
break ;
case 2:
printf("please enter the number of the employee you delete\n") ;
scanf_s("%d",&m) ;
EmpDelete(m) ;
EmpPrint() ;
break ;
default:
EmpPrint() ;
}
}
system("pause");
return 0;
}
2、约瑟夫(Josephus)环问题:编号为 1,2,3,…,n 的 n 个人按顺时针方向围坐一圈,每
人持有一个密码(正整数)。一开始任选一个正整数作为报数的上限值 m,从第一个
人开始按顺时针方向自 1 开始顺序报数,报到 m 时停止。报 m 的人出列,将他的密码
作为新的 m 值,从他在顺时针方向上的下一人开始重新从 1 报数,如此下去,直到所
有人全部出列为止。
建立 n 个人的单循环链表存储结构,运行结束后,输出依次出队的人的序号。
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
struct person
{
int num ;
int code ;
person *next ;
} ;
person *h ;
void CreaCircle()
{
int n ,i ;
person *p , *q = NULL, *r = NULL;
printf("please enterthr nember of people:\n");
scanf_s("%d",&n) ;
for(i = 1; i < n+1; i++)
{
p = (person *) malloc(sizeof(person)) ;
p->num = i ;
printf("please enter the code of the %d person:\n",i);
scanf_s("%d",&p->code) ;
p->next = NULL ;
if(i ==1)
{
h = p ;
q = p ;
}
q->next = p ;
q = p ;
}
q->next = h ;
}
void RunGame()
{
int m , i;
person * r , * t = h;
printf("please enter the rst code :\n") ;
scanf_s("%d",&m) ;
while(t->next != t)
{
for(i = 1; i < m - 1; i++)
t = t->next ;
r = t->next ;
m = r->code ;
t->next = r->next ;
printf("the %d person is kicked\n",r->num);
}
}
int main(){
CreaCircle() ;
RunGame() ;
system("pause");
return 0 ;
}
栈和队列
3、某商场有一个 100 个车位的停车场,当车位未满时,等待的车辆可以进入并计时;当
车位已满时,必须有车辆离开,等待的车辆才能进入;当车辆离开时计算停留的的时
间,并且按照每小时 1 元收费。
汽车的输入信息格式可以是(进入/离开,车牌号,进入/离开时间),要求可以随时显
示停车场内的车辆信息以及收费历史记录。
#include <iostream>
#include "time.h"
#include "stdlib.h"
#include <windows.h>
#include "stdio.h"
using namespace std;
#dene LIST_INIT_SIZE 10
#dene PRICE 1
typedef struct Car
剩余42页未读,继续阅读
资源评论
a1174675667
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 课程设计-基于深度学习的垃圾分类微信小程序源码(98高分项目).zip
- 华为S5700交换机FTP-WEB(HTTP)配置讲解.zip
- 基于MATLAB的直接序列扩频通信系统仿真
- 基于Spring Boot+Vue+ElementUI的人力资源管理系统
- AC800F编程组态培训.doc
- c++实验8-继承与派生上机练习题.doc
- CASS软件计算任意土方量操作步骤-(1).doc
- 适用于Ubuntu和手机的Yunzai-Bot一键部署脚本Ubuntu-Yunzai-master.zip
- 修复ubuntu下sublime不能输入中文的问题的脚本sublime-imfix-master.zip
- c语言中指针用法-PPT.ppt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功