Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a display method to go inside of the LinkedStack class. Display the conten

ID: 3709965 • Letter: W

Question

Write a display method to go inside of the LinkedStack class.

Display the contents like this (including the BOTTOM and TOP labels):

BOTTOM element3 element2 element1 TOP

The method header is: public void display()

Notes:

This method goes inside of the LinkedStack class, so you can directly access the instance data variables of that class.

For full credit, your methods should be efficient- O(n).

Take advantage of being able to directly access the chain of linked nodes.

Consider thinking recursively!

Explanation / Answer

public class LinkedStack { static class Node { private int data; private Node next; } private Node head; public void display() { Node temp = head; while (temp != null) { System.out.print(temp.data + " "); temp = temp.next; } System.out.println(); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote