Create a linked list in Rust: The RC smart pointer

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 มิ.ย. 2024
  • Here, I implement a linked list in Rust utilizing the RC smart pointer. You will learn about the linked list data structure as well as the Box and RC smart pointers in Rust.
    There are many other things to learn here, such as the Iterator trait, setting up a test in Rust, and much more.
    You can get the code used in this video at github.com/cudidotdev/linked-...
    Timestamps
    00:00 Introduction
    00:08 What is a Linked List?
    00:38 The Linked List and Node struct
    01:25 The Box smart pointer
    01:50 The Linked List and Node struct (contd.)
    02:44 Getting the head of a linked list list
    04:08 Pushing an element to a linked list list
    04:30 The RC smart pointer
    04:58 Pushing an element to a linked list list (contd.)
    05:35 The RC clone method
    05:45 Pushing an element to a linked list list (contd.)
    06:43 Popping an element from a linked list list
    07:32 Iterating through the elements in a linked list list
    10:04 Verifying if an element is contained in a linked list list
    11:16 Inserting ahead of a node
    11:38 Deleting ahead of a node
    11:49 Inserting an element in a linked list
    14:49 Removing an element from a linked list
    16:16 Reversing a linked list
    #rust #dsa #beginnerfriendly

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

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

    Thanks for watching. You can support me by buying me a coffee @ buymeacoffee.com/cudidotdev
    I appreciate your support. Here's a link to the code written in this video github.com/cudidotdev/linked-list-in-rust
    You can code along with me while watching the video and remember to give your feedback in the comments. Thank you

  • @neekonsaadat2532
    @neekonsaadat2532 22 วันที่ผ่านมา +1

    Hey good video, you're doing a great job

    • @cudidotdev
      @cudidotdev  21 วันที่ผ่านมา

      Thank you. This means a lot to me

  • @gertrudessampaio8689
    @gertrudessampaio8689 หลายเดือนก่อน +1

    Very nice content

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

      Thanks for the nice comments 💙

  • @nordgaren2358
    @nordgaren2358 20 วันที่ผ่านมา +1

    Shouldn't pop return the element it pops off the list?

    • @cudidotdev
      @cudidotdev  20 วันที่ผ่านมา +1

      You are right. But after removing the element, nothing points to it, so it's dropped. It would be easier if the elements implement the clone trait. I had to do a general case scenario without using any unsafe block

    • @nordgaren2358
      @nordgaren2358 20 วันที่ผ่านมา +1

      @@cudidotdev why not return the RC. Would that work? I'm not at my PC right now.
      Liked list is an interesting problem in Rust for sure! I think you did a decent job at tackling it. :)

    • @cudidotdev
      @cudidotdev  20 วันที่ผ่านมา

      I think so. You can try and let me know

    • @LtdJorge
      @LtdJorge 3 วันที่ผ่านมา +1

      @@cudidotdevI think the best way is to do the if let Some on &self.head.take(). This way, you will get ownership of the RC. Then you can call &self.head.replace() with the value obtained by calling next.

    • @cudidotdev
      @cudidotdev  วันที่ผ่านมา

      @@LtdJorge I will try that and see