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

A stack can therefore only deal with the topmost element in its storage. That\'s

ID: 3631290 • Letter: A

Question

A stack can therefore only deal with the topmost element in its storage. That's a severe limitation, but nevertheless, a stack is the basis for a lot of work in a computer: the limitation makes it easy to even implement it in hardware in the very core of your computer, the CPU.

Independent of that, we can implement a stack in JAVA just using a subset of the LinkedList commands. push = addFirst, pop = getFirst, peek = get(0). Hence, the implementation is simple. However, i do want you to implement a visualization of a stack. That means, you should visualize all elements in the stack. The underlying data structure should be Java.util.LinkedList. I leave the visualization to you. In addition, i want you to use the stack to see it in action: reverse a string using the visual stack.

So, here are your tasks:

Program a class "VisualStack", which visualizes all elements in your own stack. It must include the command push, pop, peek, and visualize all elements in the stack. Reverse a string by pushing all single characters onto the stack. Popping them from the stack and putting them together sequentially will end in the reversed string. Your visualization should show every single step.


Thank You

Explanation / Answer

import java.util.Scanner; import java.util.Stack; public class VisualStack { public static void main (String[] args) { Stack stack = new Stack(); Scanner sc = new Scanner(System.in); System.out.println("Enter a string to be reversed: "); String s = sc.nextLine(); String q = ""; System.out.println("Each instance as the string is parsed and added to the stack:"); for(int i = 0; i
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