complete push
This commit is contained in:
parent
41db07a8a3
commit
95998d4a95
1 changed files with 10 additions and 8 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -1,16 +1,17 @@
|
|||
fn main() {
|
||||
|
||||
}
|
||||
fn main() {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct List {
|
||||
head: Link
|
||||
head: Link,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Link {
|
||||
Empty,
|
||||
More(Box<Node>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Node {
|
||||
elem: i32,
|
||||
next: Link,
|
||||
|
|
@ -24,9 +25,10 @@ impl List{
|
|||
pub fn push(&mut self, elem: i32) {
|
||||
let new_node = Node {
|
||||
elem: elem,
|
||||
next: std::mem::replace(&mut self.head, Link::Empty)
|
||||
next: std::mem::replace(&mut self.head, Link::Empty),
|
||||
};
|
||||
self.head = Link::More(Box::new(new_node));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue