Advertisement
Aldin_SXR

pop()

Mar 4th, 2024 (edited)
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. /* Remove the top item from the stack, and return its data */
  2. public Data pop() {
  3.     if (isEmpty()) {                                                    // 1
  4.         throw new NoSuchElementException("The stack is empty.");        // 1
  5.     }                                                                   // 1
  6.     Data item = top.data;                                               // 2
  7.     top = top.next;                                                     // 3
  8.     size--;                                                             // 4
  9.     return item;                                                        // 5
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement