Stacks With SplStack

Поделиться
HTML-код
  • Опубликовано: 13 сен 2024

Комментарии • 3

  • @Bonestorm1990
    @Bonestorm1990 4 месяца назад

    Isn't recursion the one with depth-first and with the stack we have a breadth-first search? With the stack solution shown we are reading all elements in the current directory first and pushing new directories to the stack and then starting a new loop iteration with the last directory added to the stack. With recursion one "goes into" another recursion step as long as a directory is encountered.

  • @danielbaldwin8871
    @danielbaldwin8871 8 месяцев назад +1

    Wow. What is the benefit of using a stack object of just simply using an array? It seems that the stack object would be way slower.

    • @Bonestorm1990
      @Bonestorm1990 4 месяца назад

      You can have stack behavior with arrays (shift/unshift elements) but it arrays in PHP consume a lot of memory (because they are actual dictionaries and not "classical arrays" in other languages).