commit 5baf34fcab8df67d5f78ca35b5235ce0a50e183d
parent b9a894ee4ddce1f74a65473618b24c59eb7bf5d8
Author: ling0x <ling0x@users.noreply.github.com>
Date: Fri, 11 Sep 2026 01:50:11 +0100
vecdeque
Diffstat:
3 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/vecdeque/Cargo.lock b/vecdeque/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "vecdeque"
+version = "0.1.0"
diff --git a/vecdeque/Cargo.toml b/vecdeque/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "vecdeque"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/vecdeque/src/main.rs b/vecdeque/src/main.rs
@@ -0,0 +1,68 @@
+use std::collections::VecDeque;
+
+fn main() {
+ let mut deq = VecDeque::from([1, 2, 3]);
+ println!("Start: {:#?}", deq);
+ let memory = std::mem::size_of::<VecDeque<i32>>();
+ println!("Memory of VecDeque<i32>: {}", memory);
+
+ deq.pop_front();
+ println!("Pop front: {:#?}", deq);
+
+ deq.pop_back();
+ println!("Pop back: {:#?}", deq);
+
+ deq.push_back(100);
+ println!("Push back: {:#?}", deq);
+
+ deq.push_front(-100);
+ println!("Push front: {:#?}", deq);
+
+ //--------------- Push multiple at back ---------------------
+ deq.push_back(4);
+ deq.push_back(5);
+ deq.push_back(6);
+ deq.push_back(7);
+ deq.push_back(8);
+ println!("{:#?}", deq);
+
+ //--------------- Push multiple at front ---------------------
+ deq.push_front(-1);
+ deq.push_front(-2);
+ deq.push_front(-3);
+ deq.push_front(-4);
+ deq.push_front(-5);
+ println!("{:#?}", deq);
+
+ for (index, value) in deq.iter().enumerate() {
+ println!("Index: {}, Value: {}", index, value)
+ }
+
+ println!("=========================================================");
+ deq.remove(3);
+ for (index, value) in deq.iter().enumerate() {
+ println!("Index: {}, Value: {}", index, value)
+ }
+
+ println!("=========================================================");
+ // Returns a pair of slices which contain, in order,
+ // the contents of the deque.
+ let slices = deq.as_slices();
+ println!("Slices: {:#?}", slices);
+ // Calling partition point will be useless since VecDeque isnt sorted
+ let partition_point = deq.partition_point(|&x| x > 5);
+ println!("Partition point: {}", partition_point);
+
+ // If make_contiguous was previously called, all elements of the deque
+ // will be in the first slice and the second slice will be empty.
+ // Otherwise, the exact split point depends on implementation details
+ // and is not guaranteed.
+ deq.make_contiguous();
+ let slices = deq.as_slices();
+ println!("Slices after make_contiguous: {:#?}", slices);
+ let partition_point = deq.partition_point(|&x| x > 5);
+ println!(
+ "Partition point after make_continguous: {}",
+ partition_point
+ );
+}