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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 38 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 38 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 38 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,
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply