I just encountered a tricky algorithm problem and solved it.
Reply to discussion (solution)
$a = array(1,2,2,3,1,2,3,1,1);$st = array(1 => 0);$d = 1;foreach($a as $v) { @$st[$v]++; if($v >= $d) { $d = $v; }else{ while($v < $d) { unset($st[$d--]); } } $r[] = join('.', $st);}print_r($r); Array
(
[0] => 1
[1] => 1.1.
[2] => 1.2.
[3] => 1.2.1
[4] => 2
[5] = & gt; 2.1
[6] => 2.1.1
[7] => 3
[8] => 4
)
Sorry, I didn't see what it meant. ........ .... ............. ........ .... ........ .... ....... ....... .........
$a = array(1,2,2,3,1,2,3,1,1);$st = array(1 => 0);$d = 1;foreach($a as $v) { @$st[$v]++; if($v >= $d) { $d = $v; }else{ while($v < $d) { unset($st[$d--]); } } $r[] = join('.', $st);}print_r($r); Array
(
[0] => 1
[1] => 1.1.
[2] => 1.2.
[3] => 1.2.1
[4] => 2
[5] = & gt; 2.1
[6] => 2.1.1
[7] => 3
[8] => 4
)
Thank you for your answers. if you can, could you tell me your thoughts? thank you very much.
Sorry, I didn't see what it meant. ........ .... ............. ........ .... ........ .... ....... ....... .........
This is actually a directory arrangement problem. you can see that the priority determines the display of the size and title.
$ A = array (, 1); indicates the hierarchy of nodes
$ St = array (1 => 0); stores the current serial number of each layer
$ D indicates the current level
Well, thanks to the moderator for his explanation. I will study it and send it to you first.