feat(main): enhance demonstration of linked list operations with count tracking
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -41,14 +41,22 @@ impl<T> LinkedList<T> {
|
||||
|
||||
fn main() {
|
||||
let mut list = LinkedList::new();
|
||||
let mut count = 0;
|
||||
let message1 = "hello world";
|
||||
|
||||
// Demonstrate pushing items
|
||||
list.push_front(10);
|
||||
count += 1;
|
||||
list.push_front(20);
|
||||
count += 1;
|
||||
list.push_front(30);
|
||||
count += 1;
|
||||
|
||||
// Demonstrate peaking at the top item
|
||||
println!("Top element: {:?}", list.peek_front()); // Output: Some(30)
|
||||
// Demonstrate peeking at the top item
|
||||
if let Some(top) = list.peek_front() {
|
||||
println!("Top element: {}\ncount: {}", top, count); // Output: 30
|
||||
}
|
||||
println!("{}", message1);
|
||||
|
||||
// Demonstrate popping items
|
||||
while let Some(value) = list.pop_front() {
|
||||
|
||||
Reference in New Issue
Block a user