Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Add a Peek method to queues
Browse files Browse the repository at this point in the history
  • Loading branch information
Laifsyn committed Jun 29, 2024
1 parent 9afa650 commit 3d62ff4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ default boolean isEmpty() {

T remove();

T peek();

int len();

void clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ public T remove() {
return inner.remove_first().get();
}

@Override
public T peek() {
var e = inner.get(0);
if (e.isPresent()) {
return e.get();
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ public T remove() {
return inner.remove_first().get();
}

@Override
public T peek() {
var e = inner.get(0);
if (e.isPresent()) {
return e.get();
}
return null;
}
}

0 comments on commit 3d62ff4

Please sign in to comment.