Question
Please using a linked list to do ListStack only. Thanks Your Stack implementations will be used to do sound manipulation, namely reversing a sound clip.
Please using a linked list to do ListStack only. Thanks
Your Stack implementations will be used to do sound manipulation, namely reversing a sound clip. This process, called backmasking, was used by musicians including the Beatles, Jimi Hendrix, and Ozzy Ozbourne. You will write a program that reads a sound file in the .dat format and writes another .dat sound file which is the reverse of the first. The sample code provides a class Reverse whose main method reads in a .dat sound file, pushes all the sound values on a stack, then pops them all off and writes them into a new .dat sound file. The sample code has also provided an interface DStack, which defines a stack that holds double values. Your first job is to familiarize yourself with these files.
You need to provide two stack implementations, one using an array and one using a linked list. They should be called ArrayStack and ListStack, respectively. They should implement the DStack interface given to you. Reverse should work and create backward sound files once you complete these two implementations. Your array implementation should start with a small array (say, 10 elements) and resize it to create an array twice as large whenever the array becomes full, copying over the elements from the smaller array. While there are convenient Java library methods for copying arrays, for this assignment use your own loop to copy array elements manually (so you can see the work involved in copying). Both ArrayStack and ListStack should throw an EmptyStackException if pop() or peek() is called when the stack is empty. To use EmptyStackException, add the following line to your file: import java.util.EmptyStackException; The only Java class that you should use to complete the implementations of your stacks is java.util.EmptyStackException. You should also use the length field of an array.
DStack.java /** * Interface for a stack of primitive doubles. * * NOTE: You will * need to write something better for your implementations. */ public interface DStack { /** * is empty? */ public boolean isEmpty(); /** * push */ public void push(double d); /** * pop * @return the deleted value * @throws EmptyStackException if stack is empty */ public double pop(); /** * peek * @throws EmptyStackException if stack is empty */ public double peek(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started