今天去看书时遇到了这样两道题,自己的思路不是很清晰,请大家帮解答下,谢谢!!!例题1:用js脚本语言编写一个类Car,要求有属性color,有方法start()和stop()例题2:有三个List对象,分别是listA,listB,listC,每个List对象中存放的是Map对象的链表,每一个Map对应一条数据记录,listA中Map里存放的字段分别是id,name,age;
listB中Map里存放的字段分别是id,role;listC中Map里存放的字段分别是id,part;
编写函数public List marginList(List listA,List listB,List listC);
入参:分别为存放三张表记录的listA,listB,listC
出参:为一个将三张表合并后的新list
处理:将三个list中的id相同的记录进行合并,即将三个id相同的map合并成一个map,这个map中存放的字段id,name,age,role,part的值,然后将这些合并后的map放入新的list返回。(写出伪代码就可以了)
请各位高手帮忙谢谢!!!
listB中Map里存放的字段分别是id,role;listC中Map里存放的字段分别是id,part;
编写函数public List marginList(List listA,List listB,List listC);
入参:分别为存放三张表记录的listA,listB,listC
出参:为一个将三张表合并后的新list
处理:将三个list中的id相同的记录进行合并,即将三个id相同的map合并成一个map,这个map中存放的字段id,name,age,role,part的值,然后将这些合并后的map放入新的list返回。(写出伪代码就可以了)
请各位高手帮忙谢谢!!!
Car = function() {
this.color = null;
this.start = function() { return; }
this.stop = function() { return; }
}function List marginList(...)
var buf : Map;
begin
for (Map map : ListA)
begin
var id = map.get("id");
buf.put(id, map);
end;
for (Map map : ListB)
begin
var id = map.get("id");
if ((Map m = buf.get(id)) == null)
begin
buf.put(id, map);
end
else begin
m.put("role", map.get("role"));
buf.put(id, m);
end;
end; for (Map map : ListC)
begin
var id = map.get("id");
if ((Map m = buf.get(id)) is null)
begin
buf.put(id, map);
end
else begin
m.put("part", map.get("part"));
buf.put(id,m);
end;
end; return buf.values();
end;