双向循环链表
<?php class double_link { public $name; public $next; public $prev; public function __construct($name) { $this->name = $name; } } function get_double_link($total) { $current = $first = new double_link(1); $pre = NULL; for ($i=2; $i < $total; $i++) { $current -> next = new double_link($i); $current -> prev = $pre; $pre = $current->next; $current = $current->next; }
$first -> prev = $current; $current->prev = $pre; $current->next = $first; return $first; } var_dump(get_double_link(5));