Trees 6 recursive add

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 พ.ย. 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.

  • @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.

  • @markforest6035
    @markforest6035 7 ปีที่แล้ว +1

    Great video , Thanks you !

  • @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

  • @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 5 ปีที่แล้ว

      Remove the return your code will run...

    • @mtushar
      @mtushar 3 ปีที่แล้ว

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

  • @ahmidahmid9303
    @ahmidahmid9303 5 ปีที่แล้ว

    thanks

  • @MichaelSalo
    @MichaelSalo 4 ปีที่แล้ว

    Hammer time at 2:37