天天看點

資料結構循環連結清單

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>無标題文檔</title>

</head>

<?php

class child{

public $no;

public $next=null;

public function __construct($no){

$this->no=$no;

}

function add(&$frist,$n=4){

for($i=0;$i<$n;$i++){

$child= new child($i+1);

if($i==0){

$frist=$child;

$frist->next=$child;

$cur=$frist;

else{

$cur->next=$child;

$child->next=$frist;

$cur=$cur->next;

function showchild($frist){

while($cur->next!=$frist){

echo $cur->no."xiaohaizi<br>";

$m=2;

function countchild($frist,$m=2){

$tail=$frist;

while($tail->next!=$frist){

$tail=$tail->next;

while($tail!=$frist){

for($i=0;$i<($m-1);$i++){

$frist=$frist->next;

};

echo'<br/>出圈的人的編号是'.$frist->no;

$tail->next=$frist;

echo "<br/>最後剩下人的編号".$tail->no;

$frist=null;

add($frist,$n=100);

showchild($frist);

countchild($frist);

?>

http://blog.csdn.net/wenximalong/article/details/8299432

繼續閱讀