Arraystack, liststack, ListStackNode.java
Environment: Netbeans ,redone in Eclipse 1. Purpose The purpose of this assignment is to implement a Stack ADT in the two most common ways, an array and a linked list. You will implement stacks for Java double numbers. 2. Description 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 has provided 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. 2.1. Implementing the Stack ADT (70 points) 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 to use an array twice as large whenever the array becomes full, copying over the elements in 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. 2.2. Running Reverse (10 points) The Reverse program takes 3 arguments (also known as "command-line arguments"). The first is the word array or list and specifies which implementation to use. The next two are the input and output .dat file names (you need to include the .dat extension). Running the program will depend on your system; from a command line it will look something like: java Reverse list in.dat out.dat In an IDE there is usually a dialog box for setting program parameters which contains a field for the program arguments. (For example, in Netbeans select Build-Run Arguments and a bar will appear at the top of the screen that allows you to type in the arguments. Read more about setting command line parameters in Netbeans.) To test your program, you will need a .dat file, which you can create from a .wav file as explained in the Digital Sound section. It is also useful to create short .dat files by hand to aid testing. Note that Reverse.java just uses your stacks in one particular way: pushing a bunch of elements onto the stack and then popping them all off.
You'll get a 1.4MB .ZIP file.