Advertisement
Aldin_SXR

peek()

Mar 4th, 2024
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.24 KB | None | 0 0
  1. /* Reads an item at the top of the stack, without removing it */
  2. public Data peek() {
  3.     if (isEmpty()) {                                                // 1
  4.         throw new NoSuchElementException("Stack is empty!");        // 1
  5.     }
  6.  
  7.     return top.data;                                                // 2
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement