Page 1 of 1

class Stack private int size; private Node top: public Stack() { this.size = 0; this.top null; } public int pop() { int

Posted: Sat May 14, 2022 4:39 pm
by answerhappygod
Class Stack Private Int Size Private Node Top Public Stack This Size 0 This Top Null Public Int Pop Int 1
Class Stack Private Int Size Private Node Top Public Stack This Size 0 This Top Null Public Int Pop Int 1 (45.09 KiB) Viewed 39 times
Class Stack Private Int Size Private Node Top Public Stack This Size 0 This Top Null Public Int Pop Int 2
Class Stack Private Int Size Private Node Top Public Stack This Size 0 This Top Null Public Int Pop Int 2 (14.59 KiB) Viewed 39 times
Class Stack Private Int Size Private Node Top Public Stack This Size 0 This Top Null Public Int Pop Int 3
Class Stack Private Int Size Private Node Top Public Stack This Size 0 This Top Null Public Int Pop Int 3 (11.57 KiB) Viewed 39 times
class Stack private int size; private Node top: public Stack() { this.size = 0; this.top null; } public int pop() { int toPop = -999; if (size != 0) { toPop = top.getData(); top = top.getNextNode(); size --; // decrease the value }else{ System.out.println("Stack is now empty."); } return toPop; } public int peak(){ in toPeak -999; if (size != 0) { toPeak = top.getData(); }else{ System.out.println("Stack is now empty."); } return toPeak; public void push(int data) { Node tempNode = new Node (data); tempNode.setNextNode(top); top = tempNode; size++; // ask what this does } 9 public void display(){

public void display(){ Node temp = top: while(temp != null){ System.out.println(temp.getData()); temp = temp.getNextNode(): ; } }

Modify the stack class that we implemented in-class on April 11, using Linked List to add another method to access or search) an element at a certain index from the stack. Hint: it would be a modified version of the display() method. You would be sending the index as an argument and you keep a counter. Instead of printing all elements, you print the element only when your counter matches the index,