zoukankan      html  css  js  c++  java
  • php SPL四种常用的数据结构

    1.栈【先进后出】

    <span style="font-size:18px;">$stack = new SplStack();
    $stack->push('data1');
    $stack->push('data2');
    $stack->push('data3');
    echo $stack->pop();

    //输出结果为
    //data3</span><span style="font-size:24px;font-weight: bold;">
    </span>


    2.队列【先进先出 后进后出】

    <span style="font-size:18px;">$queue = new SplQueue();
    $queue->enqueue("data1");
    $queue->enqueue("data2");
    $queue->enqueue("data3");
    echo $queue->dequeue();
    //输出结果为
    //data1</span>

    3.堆

    <span style="font-size:18px;">$heap = new SplMinHeap();
    $heap->insert("data1");
    $heap->insert("data2");
    echo $heap->extract();
    //输出结果为
    //data1</span>


    4.固定尺寸数组

    <span style="font-size:18px;">$array = new SplFixedArray(5);
    $array[0]=1;
    $array[3]=3;
    $array[2]=2;
    var_dump($array);
    //输出结果为
    // object(SplFixedArray)[1]
    // public 0 => int 1
    // public 1 => null
    // public 2 => int 2
    // public 3 => int 3
    // public 4 => null</span>

    原文:https://blog.csdn.net/zhengwish/article/details/51742264

  • 相关阅读:
    html例题——简历
    求值
    c#语句实例(排大小)
    3.6语言基础笔记
    2016.3.5进制间的转换
    3.26-1
    3.23(网页)
    3.23
    3.22
    3.20
  • 原文地址:https://www.cnblogs.com/ivy-zheng/p/10927041.html
Copyright © 2011-2022 走看看