<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                普通的隊列是一種先進先出的數據結構,元素在隊列尾追加,而從隊列頭取出。在優先隊列中,元素被賦予優先級。當訪問元素時,具有最高優先級的元素最先取出。優先隊列具有最高級先出 (largest-in,first-out)的行為特征。 總結下來就是普通隊列有**先進先出**原則,優先級隊列有**優先級高先出**原則,這個優先級可以設置; ## 類摘要 ```php // 1. 沒有實現ArrayAccess接口,所以不能像數組那樣操作; SplPriorityQueue implements Iterator , Countable { /* 方法 */ public __construct ( void ) // 比較方法,內部應該用到了冒泡排序,對于權重值來說,返回0代表相等,返回正整數就代表大于,返回負整數就代表小于; // 默認是權重值越優先,也可以讓其被子類覆蓋改為權重值越小越優先 public int compare ( mixed $priority1 , mixed $priority2 ) public mixed extract ( void ) //恢復到上一個被破壞的節點? 測試無用; public void recoverFromCorruption ( void ) public void setExtractFlags ( int $flags ) public void insert ( mixed $value , mixed $priority ) public int count ( void ) public mixed current ( void ) public bool isEmpty ( void ) public mixed key ( void ) public void next ( void ) public void rewind ( void ) public mixed top ( void ) public bool valid ( void ) } ``` ## Example ```php class PQtest extends SplPriorityQueue { //覆蓋父類,更改其優先規則為權重值越小越優先; public function compare($priority1, $priority2) { if ($priority1 === $priority2) return 0; return $priority1 > $priority2 ? -1 : 1; } } $pq = new PQtest(); // 設置值與優先值 $pq->insert('a', 10); $pq->insert('b', 1); $pq->insert('c', 8); /** * 設置元素出隊模式 * SplPriorityQueue::EXTR_DATA 僅提取值 * SplPriorityQueue::EXTR_PRIORITY 僅提取優先級 * SplPriorityQueue::EXTR_BOTH 提取數組包含值和優先級 */ $pq->setExtractFlags(PQtest::EXTR_BOTH); //從頂部取出一個節點,該節點下面的節點移上為頂部節點; print_r( $pq->extract() ); /* [data] => b [priority] => 1 */ $pq->recoverFromCorruption(); //拿出頂部節點 print_r( $pq->extract() ); /* [data] => c [priority] => 8 */ // 還原自上一個節點? 沒什么效果? $pq->recoverFromCorruption(); print_r( $pq->current() ); $pq->rewind(); while($pq->valid()){ print_r($pq->current()); echo PHP_EOL; $pq -> next(); } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看