(&mut self, elem: T)
| 48 | } |
| 49 | |
| 50 | fn push(&mut self, elem: T) { |
| 51 | let node = Node::new(elem); |
| 52 | if self.is_empty() { |
| 53 | self.head = Some(Box::new(node)); |
| 54 | } else { |
| 55 | let mut curr = self.head.as_mut().unwrap(); |
| 56 | |
| 57 | // 找到链表最后一个节点 |
| 58 | for _i in 0..self.size-1 { |
| 59 | curr = curr.next.as_mut().unwrap(); |
| 60 | } |
| 61 | |
| 62 | // 在最后一个节点后插入新数据 |
| 63 | curr.next = Some(Box::new(node)); |
| 64 | } |
| 65 | |
| 66 | self.size += 1; |
| 67 | } |
| 68 | |
| 69 | // 栈末尾加入数据 |
| 70 | fn append(&mut self, other: &mut Self) { |