File tree 2 files changed +2
-10
lines changed
contents/stacks_and_queues/code/rust
2 files changed +2
-10
lines changed Original file line number Diff line number Diff line change @@ -14,11 +14,7 @@ impl<T> Queue<T> {
14
14
// Note that this returns a reference to the value
15
15
// This is in contrast to dequeue which gives ownership of the value
16
16
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 ( )
22
18
}
23
19
24
20
fn dequeue ( & mut self ) -> Option < T > {
Original file line number Diff line number Diff line change @@ -12,11 +12,7 @@ impl<T> Stack<T> {
12
12
// Note that this returns a reference to the value
13
13
// This is in contrast to pop which gives ownership of the value
14
14
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 ( )
20
16
}
21
17
22
18
fn pop ( & mut self ) -> Option < T > {
You can’t perform that action at this time.
0 commit comments