数据结构与算法描述(第三章案例介绍)
来源:互联网 发布:美萍汽车维修软件 编辑:程序博客网 时间:2024/04/30 02:38
//显示现有的影碟清单
function displayList(list) {
for(var i = 0;i < list.length();++i) {
if(list.getElement() instanceof Customer) {
console.log(list.getElement().name + "," +list.getElement().movie);
list.next();
} else {
console.log(list.getElement());
list.next();
}
}
list.front();
}
//允许客户检出电影的函数
function checkOut(name,movie,filmList,customerList) {
if(movieList.contains(movie)) {
var c = new Customer(name,movie);
customerList.append(c);
var remove = filmList.remove(movie);
lendedlist.append(remove);
showLended();
} else {
console.log(movie + "is not available");
}
}
function showLended() {
console.log("已经出租的影片有:");
console.log(JSON.stringify(lendedlist.showList()));
}
function check_in(name,returning) {
lendedlist.remove(returning);
movieList.append(returning);
console.log(name + "归还影片:" + returning);
}
function Customer(name,movie) { //Customer对象
this.name = name;
this.movie = movie;
}
//测试
var movies = ["movie_first","movie_second","movie_third","movie_forth","movie_fifth"];
var movieList = new List(); //保存电影
var customers = new List(); //用来保存在系统中检出电影的客户
var lendedlist = new List(); //已出租列表
//将电影数组保存到一个列表中
for (var i = 0;i < movies.length;++i) {
movieList.append(movies[i]);
}
console.log("目前还可以租借的电影有:");
displayList(movieList);
console.log("将为xq检出电影movie_second");
checkOut("xq","movie_second",movieList,customers);
console.log("将为xq检出电影movie_first");
checkOut("xq","movie_first",movieList,customers);
console.log("已经租借的客户信息:");
displayList(customers);
console.log("现在还可以租借的电影有:");
displayList(movieList);
checkOut("xq","movie_third",movieList,customers);
console.log("已经租借的客户信息:");
displayList(customers);
console.log("现在还可以租借的电影有:");
displayList(movieList);
check_in("xq","movie_second");
console.log("现在还可以租借的电影有:");
displayList(movieList);
function displayList(list) {
for(var i = 0;i < list.length();++i) {
if(list.getElement() instanceof Customer) {
console.log(list.getElement().name + "," +list.getElement().movie);
list.next();
} else {
console.log(list.getElement());
list.next();
}
}
list.front();
}
//允许客户检出电影的函数
function checkOut(name,movie,filmList,customerList) {
if(movieList.contains(movie)) {
var c = new Customer(name,movie);
customerList.append(c);
var remove = filmList.remove(movie);
lendedlist.append(remove);
showLended();
} else {
console.log(movie + "is not available");
}
}
function showLended() {
console.log("已经出租的影片有:");
console.log(JSON.stringify(lendedlist.showList()));
}
function check_in(name,returning) {
lendedlist.remove(returning);
movieList.append(returning);
console.log(name + "归还影片:" + returning);
}
function Customer(name,movie) { //Customer对象
this.name = name;
this.movie = movie;
}
//测试
var movies = ["movie_first","movie_second","movie_third","movie_forth","movie_fifth"];
var movieList = new List(); //保存电影
var customers = new List(); //用来保存在系统中检出电影的客户
var lendedlist = new List(); //已出租列表
//将电影数组保存到一个列表中
for (var i = 0;i < movies.length;++i) {
movieList.append(movies[i]);
}
console.log("目前还可以租借的电影有:");
displayList(movieList);
console.log("将为xq检出电影movie_second");
checkOut("xq","movie_second",movieList,customers);
console.log("将为xq检出电影movie_first");
checkOut("xq","movie_first",movieList,customers);
console.log("已经租借的客户信息:");
displayList(customers);
console.log("现在还可以租借的电影有:");
displayList(movieList);
checkOut("xq","movie_third",movieList,customers);
console.log("已经租借的客户信息:");
displayList(customers);
console.log("现在还可以租借的电影有:");
displayList(movieList);
check_in("xq","movie_second");
console.log("现在还可以租借的电影有:");
displayList(movieList);
0 0
- 数据结构与算法描述(第三章案例介绍)
- 数据结构与算法描述(第三章示例)
- 数据结构与算法C语言描述 第三章练习
- 第三章:数据结构与算法javascript描述: 列表
- 数据结构与算法JavaScript描述[第三章](列表)
- 数据结构与算法C#语言描述第三章基础排序算法
- 算法与数据结构描述
- 《数据结构与算法分析--C++描述》(第三版)学习笔记系列一:BST的实现
- 数据结构与算法第三章
- 数据结构与算法描述第(第二章示例)
- 《数据结构与算法JavaScript描述》
- 《数据结构与算法分析C++描述(第3版)》第三章List容器可编译运行版
- 数据结构与算法分析学习笔记---第三章(链表)
- 【数据结构与算法分析 】第三章总结
- 数据结构与算法-排序与查找(java描述)
- 数据结构与算法JavaScript描述[第二章](数组)
- 数据结构与算法JavaScript描述[第五章](队列)
- 数据结构与算法JavaScript描述[第六章](链表)
- Java PermGen 去哪里了?
- 利用URLConnection来发送POST和GET请求
- struts工作顺序
- 接口与抽象类与继承
- 工作心得
- 数据结构与算法描述(第三章案例介绍)
- SQL对时间处理的语句小结
- CentOS下挂载NTFS格式的磁盘
- 怎么获取局域网内其他计算机的IP地址
- android适配需要知道的一些概念
- struts.xml 配置package标签里面的属性
- 9Club Online Casino Free Credit Beat Baccarat
- es批量搜索
- 基于RxJava的RxBus