<script>
//递归+交换
function pailie1()
{
let arr=[1,2,3];
const len=arr.length;
let total=0;
function f1(start)
{
if(start==len)
{
document.write(`${arr}<br />`);
total++;
}
for(let i=start;i<len;i++)
{
[arr[start],arr[i]]=[arr[i],arr[start]];
f1(start+1);
[arr[start],arr[i]]=[arr[i],arr[start]];
}
}
f1(0);
document.write(`total1=${total}<br /><br />`);
}
pailie1();
</script>

//递归+交换
function pailie1()
{
let arr=[1,2,3];
const len=arr.length;
let total=0;
function f1(start)
{
if(start==len)
{
document.write(`${arr}<br />`);
total++;
}
for(let i=start;i<len;i++)
{
[arr[start],arr[i]]=[arr[i],arr[start]];
f1(start+1);
[arr[start],arr[i]]=[arr[i],arr[start]];
}
}
f1(0);
document.write(`total1=${total}<br /><br />`);
}
pailie1();
</script>

