Singly-Linked List in Rust

[Some(ptr)] -> (1, Some(ptr)) -> (2, None)Stack: push(3)
[Some(ptr)] -> (3, Some(ptr)) -> (1, Some(ptr))-> (2, None)
Stack: pop()
[Some(ptr)] -> (1, Some(ptr))-> (2, None)
Queue: add(4)
[Some(ptr)] -> (1, Some(ptr)) -> (2, Some(ptr))-> (4, None)
Queue: remove()
[Some(ptr)] -> (2, Some(ptr))-> (4, None)
struct SLList<T> {
head: Link<T>,
tail: *mut Node<T>,
}
type Link<T> = Option<Box<Node<T>>>;struct Node<T> {
elem: T,
next: Link<T>,
}

参考

--

--

--

Software engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Takanori Ishibashi

Takanori Ishibashi

Software engineer

More from Medium

How Rust can be used to Implement a better Operating System — Part 2

Rust Language Notes — Part 2

Leaf Traversal | Rust

Base64 Encoding Implementation in Rust