Trees 6 recursive add

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 12

  • @guillermoperez8250
    @guillermoperez8250 5 років тому +1

    Awesome. Just one typo: the overloaded method should be private, otherwise the counter will never be run. Also, making the insert position public doesn't sound like a good idea because people would mess it up.

  • @markforest6035
    @markforest6035 7 років тому +1

    Great video , Thanks you !

  • @daleoking1
    @daleoking1 7 років тому +1

    Hello. Great videos first of all. Second: when you add a new node_Object, you increment the size of the tree(currentSize++) correct? So in this case the field variable currentSize represents the number of nodes in the tree and not the height right?!

    • @markforest6035
      @markforest6035 7 років тому

      Right because the currentSize++ established only at the end of the function , and its represent the number of all nodes in the tree.

  • @ahmidahmid9303
    @ahmidahmid9303 5 років тому

    thanks

  • @MichaelSalo
    @MichaelSalo 4 роки тому

    Hammer time at 2:37

  • @tonysmiah
    @tonysmiah 5 років тому

    Can someone please confirm if this code compiles? Because it's a void return method, why are we returning a recursive add method? Thanks

    • @Shu-gm2xx
      @Shu-gm2xx 4 роки тому

      Remove the return your code will run...

    • @mtushar
      @mtushar 2 роки тому

      the add method returns null, so returning a add() call returns the return of it which is null when the recursive stack terminates.

  • @karenjang5201
    @karenjang5201 6 років тому +1

    why do you use return for either "return add(obj, node.right)"
    or "return add(obj, node.left) in the 2nd method? It is void method, so I thought you can call it without return

    • @guillermoperez8250
      @guillermoperez8250 5 років тому

      I think he uses return to prevent next lines to be executed. And eventually, you'll always be returning null. Because the actual insertion returns null. The calls you mention return what the recursive call returns... and that will always be null if the insertion succeded.

    • @ahmidahmid9303
      @ahmidahmid9303 5 років тому

      @@guillermoperez8250 no he is returning void not null