Advertisement
Aldin-SXR

pop()

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