第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 SplDoublyLinkedList 模仿這個雙向鏈表動畫?

如何使用 SplDoublyLinkedList 模仿這個雙向鏈表動畫?

PHP
慕勒3428872 2021-11-13 19:08:08
我試圖對使用此工具生成的雙向鏈表動畫進行逆向工程:所以我試過這個:<?php$dll = new \SplDoublyLinkedList();$dll->unshift(200);//inserir no início$dll->unshift(100);//inserir no início$dll->push(34);//inserir no final$dll->push(35);//inserir no final$dll->add(2, 3); //inserir em posicao específica$dll->unshift(670);//inserir no início$dll->add(($dll->count() / 2)-1, 450);//inserir no meio$dll->pop(); //remover do final$dll->shift(); //remover do início$dll->offsetUnset(1);//remover de posicao específica$prev = null;$dll->rewind(); //rebobinandowhile ($dll->valid()) {    $current = $dll->current();    echo 'Atual: '.$current, "\n";    $dll->next();}但是結(jié)果與動畫不同:(如何模仿這個雙向鏈表動畫并獲得相同的結(jié)果?
查看完整描述

1 回答

?
哆啦的時光機

TA貢獻1779條經(jīng)驗 獲得超6個贊

我不認為您可以使用純 PHP 來模仿該動畫,至少這并不容易。您可以通過在每個步驟打印列表內(nèi)容來以某種方式為列表內(nèi)容的輸出設(shè)置動畫,并使用sleep以便能夠觀察輸出的更改:


<?php


$dll = new \SplDoublyLinkedList();


// add 200 to the list using push. Unshift has the same effect because the list is empty

$dll->push(200);

output($dll);


// insert 100 at the beginning of the list

$dll->unshift(100); 

output($dll);


// add 34 the end of the list

$dll->push(34); 

output($dll);


// add 35 the end of the list

$dll->push(35);

output($dll);


// insert 3 on the second position (usually a loop to find the index would be necessary)

$dll->add(2, 3);

output($dll);


// insert 670 at the beginning of the list

$dll->unshift(670);

output($dll);


// add 450 on the third position 

$dll->add(3, 450);

output($dll);


// remove last element of the list

$dll->pop();

output($dll);


// remove first element of the list

$dll->shift();

output($dll);


// remove from position 1 (second linked list element)

$dll->offsetUnset(1); 

output($dll);


function output(&$dll) {

    ob_start();


    $dll->rewind();


    $values = [];

    while ($dll->valid()) {

        $values[] = $dll->current();

        $dll->next();

    }


    echo "[ " . implode(' , ', $values) . " ] \n"; //on the browser change \n to <br>


    ob_end_flush();

    //ob_flush(); // enable on the browser

    flush();


    sleep(1); // wait one second

}


查看完整回答
反對 回復(fù) 2021-11-13
  • 1 回答
  • 0 關(guān)注
  • 155 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號