一元表的交集、相加、相减、打包元组
import console;A = {1,2,3};
B = {5,3};
console.log("表A:")
console.dumpTable(A)
console.log("表B:")
console.dumpTable(B)
var 集合交集 = function(A,B){
for(k,v in A){
for(i=1;#B;1){
if(table.find(A,B)=null){
table.removeByValue(B,B)
}
}
}
return B;
}
console.log("集合交集(A,B):")
console.dumpTable(集合交集(A,B));
console.pause(true);
A = {1,2,3};
B = {5,3};
console.log("表A:")
console.dumpTable(A)
console.log("表B:")
console.dumpTable(B)
var 集合相加 = function(A,B){
for(n=1;#B;1){
if(table.find(A,B)=null){
//console.log(B)
table.push(A,B)
}
}
return A;
}
console.log("集合相加(A,B):")
console.dumpTable(集合相加(A,B));
console.pause(true);
A = {1,2,3};
B = {5,3};
console.log("表A:")
console.dumpTable(A)
console.log("表B:")
console.dumpTable(B)
var 集合相减 = function(A,B){
for(n=1;#B;1){
for(i=1;#B;1){
if(table.find(A,B)!=null){
table.removeByValue(A,B)
}
}
}
return A;
}
console.log("集合相减(A,B):")
console.dumpTable(集合相减(A,B));
console.pause(true);
A = {5,3};
B = {1,2,3};
console.log("表A:")
console.dumpTable(A)
console.log("表B:")
console.dumpTable(B)
var 打包元组 = function(A,B){
var C = {};
for(k,v in A){
C=B
}
return C;
}
console.log("打包元组(A,B):")
console.varDump(打包元组(A,B));
console.pause(true);
请教一下楼主,【集合相减】里,为何 for(n=1;#B;1)循环里再套一个同样的循环呢?
页:
[1]