< h t m l >
< h e a d >
< s c r i p t >
function page()
{
f1.doc ment.op en();
f1.doc ment.w rite('小于h3>Print out all subsets of a given set小于/h3>');
f1.doc ment.w rite('小于 fo rm name=fm>');
f1.doc ment.w rite('Please type your set: 小于input type=text name=set size=30>');
f1.doc ment.w rite('小于input type=button value="Sub mit" onClick="parent.subsets(set.value);">');
f1.doc ment.w rite('小于fo rm>');
f1.doc ment.cl ose();
}
function subsets(str1)
{
var str = str1.replace(/W/g,'');
var sets = str.split('');
var num = str.length;
var ii, hh, count=1;
var idx = new Array();
f2.doc ment.op en();
if(num == 0)
{
f2.doc ment.w rite('Empty set');
f2.doc ment.cl ose();
return;
}
f2.doc ment.w rite('input set: ');
f2.doc ment.w rite(str);
f2.doc ment.w rite('小于br>n');
f2.doc ment.w rite('All subsets:小于br>n');
for(ii = 0; ii < num; ii++)
{
for(hh = 0; hh <= ii; hh++)
{
idx[hh] = hh;
}
while(1)
{
f2.doc ment.w rite(count++ + ': ');
for(hh = 0; hh <= ii; hh++)
{
f2.doc ment.w rite(sets[idx[hh]]);
}
f2.doc ment.w rite("小于br>n");
if(idx[ii] < num - 1)
{
idx[ii]++;
}
else
{
for(hh = ii - 1; hh >= 0; hh--)
{
if(idx[hh] < num - 1 - (ii - hh))
{
idx[hh]++;
break;
}
}
if(hh < 0)
{
break;
}
while(++hh <= ii)
{
idx[hh] = idx[hh-1] + 1;
}
}
}
}
f2.doc ment.cl ose();
}
< /s c r i p t >
< /h e a d >
< f r a m e s e t rows="20%,80%" >
< f r a m e name=f1 src="java s c r i p t:parent.page();" >
< f r a m e name=f2 src="java s c r i p t:parent.subsets('');" >
< /f ra meset >
< /h t m l >