Rust Programming Exercises: Binary Search

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 พ.ย. 2024

ความคิดเห็น • 9

  • @tvboyd23
    @tvboyd23 2 ปีที่แล้ว +7

    You forgot to catch the overflow bug in your midpoint calculation. `(l + r) / 2` can overflow because you're adding 2 variable integers. Instead you can use `l + (r - l) / 2` which is safu from overflow as long as you know that l < r, which you do in this case.

  • @darkenblade986
    @darkenblade986 2 ปีที่แล้ว +4

    Just a tip dont use else on an if statement with a return. other than that cool stuff did not know about cmp

  • @sangamo38
    @sangamo38 2 ปีที่แล้ว +3

    can you share your setup details, which extension is it with neovim.

  • @hairuilin829
    @hairuilin829 ปีที่แล้ว

    Thank you so much for your videos. I am starting on rust and i am learnign a lot from your videos. I sincerely hope you can continue making more.
    one small thing to call out, probably also needs double checking from you is that, when we define the input parameter as `AsRef`, we need to be cautious that the function still takes ownership from the input parameter. So in this case, using the function you have defined in the video, once a vector is used for binary search, it is no longer usable.
    I think if that is right, then from the design perspective, it may be better to make the input parameter simply &[T]?

  • @MrAnandml
    @MrAnandml 2 ปีที่แล้ว +1

    You deserve more subs pal ...such great content.

  • @paulineputrolaynen
    @paulineputrolaynen 10 หลายเดือนก่อน

    Thanks a lot for your explanation. I tried this code and found that the case when L equals R is not handled. I guess this case is possible.

  • @RichardNatal
    @RichardNatal 2 ปีที่แล้ว +1

    how did you structured your code so you can have the tests in a total separated directory?

  • @vishalgupta8986
    @vishalgupta8986 2 ปีที่แล้ว

    Can you please tell if instead of "return Some(mid);" when i used "Some(mid)" it gave error. Why?

    • @vishalgupta8986
      @vishalgupta8986 2 ปีที่แล้ว

      @@nyxtom understood if within your program you are going to return from more than one location you have to use return in all them except the default one.
      Thanks