Advertisement
Aldin_SXR

push()

Mar 4th, 2024
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.25 KB | None | 0 0
  1. /* Push an item onto the stack */
  2. public void push(Data item) {
  3.     Node<Data> newNode = new Node<>();      // 1
  4.     newNode.data = item;                    // 1
  5.     newNode.next = top;                     // 2
  6.     top = newNode;                          // 3
  7.     size++;                                 // 4
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement