main.rs (2184B)
1 use std::collections::VecDeque; 2 3 fn main() { 4 let mut deq = VecDeque::from([1, 2, 3]); 5 println!("Start: {:#?}", deq); 6 let memory = std::mem::size_of::<VecDeque<i32>>(); 7 println!("Memory of VecDeque<i32>: {}", memory); 8 9 deq.pop_front(); 10 println!("Pop front: {:#?}", deq); 11 12 deq.pop_back(); 13 println!("Pop back: {:#?}", deq); 14 15 deq.push_back(100); 16 println!("Push back: {:#?}", deq); 17 18 deq.push_front(-100); 19 println!("Push front: {:#?}", deq); 20 21 //--------------- Push multiple at back --------------------- 22 deq.push_back(4); 23 deq.push_back(5); 24 deq.push_back(6); 25 deq.push_back(7); 26 deq.push_back(8); 27 println!("{:#?}", deq); 28 29 //--------------- Push multiple at front --------------------- 30 deq.push_front(-1); 31 deq.push_front(-2); 32 deq.push_front(-3); 33 deq.push_front(-4); 34 deq.push_front(-5); 35 println!("{:#?}", deq); 36 37 for (index, value) in deq.iter().enumerate() { 38 println!("Index: {}, Value: {}", index, value) 39 } 40 41 println!("========================================================="); 42 deq.remove(3); 43 for (index, value) in deq.iter().enumerate() { 44 println!("Index: {}, Value: {}", index, value) 45 } 46 47 println!("========================================================="); 48 // Returns a pair of slices which contain, in order, 49 // the contents of the deque. 50 let slices = deq.as_slices(); 51 println!("Slices: {:#?}", slices); 52 // Calling partition point will be useless since VecDeque isnt sorted 53 let partition_point = deq.partition_point(|&x| x > 5); 54 println!("Partition point: {}", partition_point); 55 56 // If make_contiguous was previously called, all elements of the deque 57 // will be in the first slice and the second slice will be empty. 58 // Otherwise, the exact split point depends on implementation details 59 // and is not guaranteed. 60 deq.make_contiguous(); 61 let slices = deq.as_slices(); 62 println!("Slices after make_contiguous: {:#?}", slices); 63 let partition_point = deq.partition_point(|&x| x > 5); 64 println!( 65 "Partition point after make_continguous: {}", 66 partition_point 67 ); 68 }