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