Skip to content

Commit 962e854

Browse files
Use equivalent methods instead of reimplementing them
1 parent 2b1379a commit 962e854

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

contents/stacks_and_queues/code/rust/Queue.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ impl<T> Queue<T> {
1414
// Note that this returns a reference to the value
1515
// This is in contrast to dequeue which gives ownership of the value
1616
fn front(&self) -> Option<&T> {
17-
if self.list.len() > 0 {
18-
Some(&self.list[0])
19-
} else {
20-
None
21-
}
17+
self.list.front()
2218
}
2319

2420
fn dequeue(&mut self) -> Option<T> {

contents/stacks_and_queues/code/rust/Stack.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ impl<T> Stack<T> {
1212
// Note that this returns a reference to the value
1313
// This is in contrast to pop which gives ownership of the value
1414
fn top(&self) -> Option<&T> {
15-
if self.list.len() > 0 {
16-
Some(&self.list[self.list.len() - 1])
17-
} else {
18-
None
19-
}
15+
self.list.last()
2016
}
2117

2218
fn pop(&mut self) -> Option<T> {

0 commit comments

Comments
 (0)