MCPcopy Create free account
hub / github.com/douchuan/algorithm / t_has_cycle

Function t_has_cycle

src/ll/cycle.rs:30–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28
29#[test]
30fn t_has_cycle() {
31 let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
32 let mut ll = LinkedList::default();
33 for v in data {
34 ll.push_back(v);
35 }
36
37 //no cycle
38 assert!(!has_cycle(ll.head));
39
40 //create cycle by hand
41 let mut tail = ll.tail.unwrap();
42 unsafe {
43 tail.as_mut().next = ll.head;
44 }
45 assert!(has_cycle(ll.head));
46
47 //eliminate cycle, otherwise LinkedList drop failed
48 unsafe {
49 tail.as_mut().next = None;
50 }
51}

Callers

nothing calls this directly

Calls 1

push_backMethod · 0.80

Tested by

no test coverage detected