MCPcopy Index your code
hub / github.com/QMHTMY/RustBook / push

Method push

publication/code/chapter04/lvec.rs:51–68  ·  view source on GitHub ↗
(&mut self, elem: T)

Source from the content-addressed store, hash-verified

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) {

Callers 15

newMethod · 0.45
clearMethod · 0.45
iterMethod · 0.45
iter_mutMethod · 0.45
sortMethod · 0.45
bucket_sortFunction · 0.45
mergeFunction · 0.45
sortMethod · 0.45
appendMethod · 0.45
basicFunction · 0.45
iterFunction · 0.45
iterMethod · 0.45

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected