js 环形链表
function link($no)
{
this.no = $no;
this.next;
}
function addLink($num)
{
var $first=$cur = {};
for(var $i=1;$i<=$num;$i++)
{
var $link = new link($i);
if($i==1){
$first = $link;
$first.next = $first;
$cur = $first;
}else{
$cur.next = $link;
$link.next = $first;
$cur = $cur.next;
}
}
return $first;
}
$link = addLink(15);
console.log($link);
{
this.no = $no;
this.next;
}
function addLink($num)
{
var $first=$cur = {};
for(var $i=1;$i<=$num;$i++)
{
var $link = new link($i);
if($i==1){
$first = $link;
$first.next = $first;
$cur = $first;
}else{
$cur.next = $link;
$link.next = $first;
$cur = $cur.next;
}
}
return $first;
}
$link = addLink(15);
console.log($link);