Sound Reader Class Path Projects

Soundreaderclasspathsoundreaderprojectsoundreader

Soundreaderclasspathsoundreaderprojectsoundreader

Soundreader/.classpath Soundreader/.project Soundreader org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature Soundreader/.settings/org.eclipse.jdt.core.prefs eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.8 Soundreader/bin/ArrayStack.class public synchronized class ArrayStack { private Object[] data ; private int size ; public void ArrayStack(); public boolean isEmpty (); protected boolean isFull (); public Object peek (); public Object pop (); public void push (Object); protected void stretch (); } Soundreader/bin/DStack.class public abstract interface DStack { public abstract boolean isEmpty (); public abstract void push (double); public abstract double pop (); public abstract double peek (); } Soundreader/bin/gtd/stack/ListStackNode.class package gtd.stack; public final synchronized class ListStackNode { private static final EpsilonStackNode EMPTY ; private final String nodeName ; private final AbstractStackNode[] children ; private final AbstractStackNode emptyChild ; public void ListStackNode(int, int, AbstractStackNode, String, boolean); private void ListStackNode(ListStackNode, int); AbstractStackNode[] generateChildren (AbstractStackNode); private AbstractStackNode generateEmptyChild (); public String getName (); public AbstractStackNode getCleanCopy (int); public AbstractStackNode[] getChildren (); public boolean canBeEmpty (); public AbstractStackNode getEmptyChild (); public String toString (); } Soundreader/bin/ListStack.class public synchronized class ListStack { private ListNode topOfStack ; public void ListStack(); public boolean isEmpty (); public void makeEmpty (); public void push (Object); public void pop (); public Object top (); public Object topAndPop (); } Soundreader/bin/Reverse.class public synchronized class Reverse { public void Reverse(); public static void main (String[]); } Soundreader/Screenshot (14).png Soundreader/Screenshot (15).png Soundreader/Screenshot (16).png Soundreader/src/ArrayStack.java Soundreader/src/ArrayStack.java import java . util .

EmptyStackException ; public class ArrayStack implements DStack { / Array of items in this Stack. / private E [] data ; / Number of items currently in this Stack. / private int size ; / The Stack is initally empty. / public ArrayStack () { data = ( E [])( new Object [ 1 ]); // This causes a compiler warning size = 0 ; } public boolean isEmpty () { return size == 0 ; } / Return true if data is full. / protected boolean isFull () { return size == data . length ; } public E peek () { if ( isEmpty ()) { throw new EmptyStackException (); } return data [ size - 1 ]; } public E pop () { if ( isEmpty ()) { throw new EmptyStackException (); } size -- ; return data [ size ]; } public void push ( E target ) { if ( isFull ()) { stretch (); } data [ size ] = target ; size ++ ; } / Double the length of data. / protected void stretch () { E [] newData = ( E [])( new Object [ data . length 2 ]); // Warning for ( int i = 0 ; i Interface for a stack of primitive doubles. @version NOTE: The comments for this interface are horrible!

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 (); } Soundreader/src/gtd/stack/ListStackNode.java Soundreader/src/gtd/stack/ListStackNode.java package gtd . stack ; public final class ListStackNode extends AbstractExpandableStackNode { private final static EpsilonStackNode EMPTY = new EpsilonStackNode ( DEFAULT_LIST_EPSILON_ID , 0 ); private final String nodeName ; private final AbstractStackNode [] children ; private final AbstractStackNode emptyChild ; public ListStackNode ( int id , int dot , AbstractStackNode child , String nodeName , boolean isPlusList ){ super ( id , dot ); this . nodeName = nodeName ; this . children = generateChildren ( child ); this . emptyChild = isPlusList ? null : generateEmptyChild (); } private ListStackNode ( ListStackNode original , int startLocation ){ super ( original , startLocation ); nodeName = original . nodeName ; children = original . children ; emptyChild = original . emptyChild ; } private AbstractStackNode [] generateChildren ( AbstractStackNode child ){ AbstractStackNode listNode = child . getCleanCopy ( DEFAULT_START_LOCATION ); listNode . markAsEndNode (); listNode . setProduction ( new AbstractStackNode []{ listNode , listNode }); return new AbstractStackNode []{ listNode }; } private AbstractStackNode generateEmptyChild (){ AbstractStackNode empty = EMPTY . getCleanCopy ( DEFAULT_START_LOCATION ); empty . setProduction ( new AbstractStackNode []{ empty }); empty . markAsEndNode (); return empty ; } public String getName (){ return nodeName ; } public AbstractStackNode getCleanCopy ( int startLocation ){ return new ListStackNode ( this , startLocation ); } public AbstractStackNode [] getChildren (){ return children ; } public boolean canBeEmpty (){ return ( emptyChild != null ); } public AbstractStackNode getEmptyChild (){ return emptyChild ; } public String toString (){ StringBuilder sb = new StringBuilder (); sb . append ( nodeName ); sb . append ( getId ()); sb . append ( '(' ); sb . append ( startLocation ); sb . append ( ')' ); return sb .toString (); } } Soundreader/src/ListStack.java Soundreader/src/ListStack.java // ListStack class // // CONSTRUCTION: with no initializer // // PUBLIC OPERATIONS // void push( x ) --> Insert x // void pop( ) --> Remove most recently inserted item // AnyType top( ) --> Return most recently inserted item // AnyType topAndPop( ) --> Return and remove most recent item // boolean isEmpty( ) --> Return true if empty; else false // void makeEmpty( ) --> Remove all items // ERRORS* // top, pop, or topAndPop on empty stack public class ListStack implements DStack { / Construct the stack. / public ListStack ( ) { topOfStack = null ; } / Test if the stack is logically empty. @return true if empty, false otherwise. / public boolean isEmpty ( ) { return topOfStack == null ; } / Make the stack logically empty. / public void makeEmpty ( ) { topOfStack = null ; } / Insert a new item into the stack. @param x the item to insert. / public void push ( AnyType x ) { topOfStack = new ListNode ( x , topOfStack ); } / Remove the most recently inserted item from the stack. @throws UnderflowException if the stack is empty. / public void pop ( ) { if ( isEmpty ( ) ) throw new UnderflowException ( "ListStack pop" ); topOfStack = topOfStack . next ; } / Get the most recently inserted item in the stack. Does not alter the stack. @return the most recently inserted item in the stack. @throws UnderflowException if the stack is empty. / public AnyType top ( ) { if ( isEmpty ( ) ) throw new UnderflowException ( "ListStack top" ); return topOfStack . element ; } / Return and remove the most recently inserted item from the stack. @return the most recently inserted item in the stack. @throws UnderflowException if the stack is empty. / public AnyType topAndPop ( ) { if ( isEmpty ( ) ) throw new UnderflowException ( "ListStack topAndPop" ); AnyType topItem = topOfStack . element ; topOfStack = topOfStack . next ; return topItem ; } private ListNode topOfStack ; } Soundreader/src/Reverse.java Soundreader/src/Reverse.java import java . io .

BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io .

PrintWriter ; import java . util . StringTokenizer ; /* Read a .dat file and reverse it. @version / public class Reverse { public static void main ( String [] args ) { if ( args . length != 3 ) { System . err . println ( " Incorrect number of arguments" ); System . err . println ( " Usage: " ); System . err . println ( "\tjava Reverse " ); System . exit ( 1 ); } boolean useList = true ; if ( args [ 0 ]. compareTo ( "list" ) == 0 ) useList = true ; else if ( args [ 0 ]. compareTo ( "array" ) == 0 ) useList = false ; else { System . err . println ( "\tSaw " + args [ 0 ] + " instead of list or array as first argument" ); System . exit ( 1 ); } try { // // Set up the input file to read, and the output file to write to // BufferedReader fileIn = new BufferedReader ( new FileReader ( args [ 1 ])); PrintWriter fileOut = new PrintWriter ( new BufferedWriter ( new FileWriter ( args [ 2 ]))); // // Read the first line of the .dat file to get sample rate. // We want to store the sample rate value in a variable, // but we can ignore the "; Sample Rate" part of the line. // Step through the first line one token (word) at a time // using the StringTokenizer.

The fourth token is the one // we want (the sample rate). // StringTokenizer str ; String oneLine ; int sampleRate ; String strJunk ; oneLine = fileIn . readLine (); str = new StringTokenizer ( oneLine ); strJunk = str . nextToken (); // Read in semicolon strJunk = str . nextToken (); // Read in "Sample" strJunk = str . nextToken (); // Read in "Rate" // Read in sample rate sampleRate = Integer . parseInt ( str . nextToken ()); // // Read in the remainder of the file on line at a time. // The values in the first column are thrown away. // Place values from the second column on the stack. // Stop reading if we reach the end of the file. // DStack s ; if ( useList ) s = new ListStack (); else s = new ArrayStack (); String timestep ; double data ; int count = 0 ; while (( oneLine = fileIn . readLine ()) != null ) { if ( oneLine . charAt ( 0 ) == ';' ) { continue ; } str = new StringTokenizer ( oneLine ); // Read in time step value from first column timestep = str . nextToken (); // Read in data value from second column data = Double . parseDouble ( str . nextToken ()); s . push ( data ); count ++ ; } System . out . println ( count + " samples in file" ); // // Print the data values to output .dat file. // First, output the header line: // "; Sample Rate " // fileOut . println ( "; Sample Rate " + sampleRate ); // Since the first column consists of numbers which start // at 0 and increase by 1/sampleRate every time slice, we'll // just use numSteps to recalculate these numbers. int numSteps = 0 ; // Finally, we print the values in reverse order (by popping // them off the stack). The first column consists of numbers // which start at 0 and increase by 1/sampleRate per row, so // we'll use numSteps/sampleRate to recalculate the appropriate // values. Print a tab for uniform spacing. while ( ! s . isEmpty ()) { fileOut . println (( double ) numSteps / sampleRate + "\t" + s . pop ()); numSteps ++ ; } // // Close the files // fileIn . close (); fileOut . close (); } catch ( IOException ioe ) { System . err . println ( "Error opening/reading/writing input or output file." ); System . exit ( 1 ); } catch ( NumberFormatException nfe ) { System . err . println ( nfe . toString ()); System . err . println ( "Error in file format" ); System . exit ( 1 ); } } }

Paper For Above instruction

In the realm of computer science and software engineering, understanding data structures such as stacks is fundamental for efficient data management and algorithm implementation. Stack data structures operate on the Last-In-First-Out (LIFO) principle, making them ideal for tasks requiring reversible or recursive operations. This essay elaborates on various aspects of stack implementations, focusing on array-based and linked-list-based stacks, and explores their applications in reversing data sequences, a common use case in signal processing, management of function calls, and backtracking algorithms.

The ArrayStack class exemplifies an array-based implementation of a generic stack in Java. It utilizes a dynamically resized array to store elements, providing efficient push and pop operations. The push method checks if the array is full before adding a new element; if it is, the stretch method doubles the array size to accommodate additional data. This approach ensures that the stack can grow dynamically, maintaining performance efficiency. The peek method retrieves the top element without removing it, while the pop method removes and returns the top element, throwing an EmptyStackException if the stack is empty. These operations conform to the expected LIFO behavior, ensuring data integrity during manipulation.

Linked-list-based stacks, such as the ListStack class, offer an alternative that naturally supports dynamic resizing without the need for array resizing. Here, each new element is encapsulated within a ListNode, which is linked to the previous node. This implementation provides constant-time operations for push, pop, and top, making it highly suitable for applications where the size of the data set fluctuates unpredictably. The ListStack functionality extends to methods like makeEmpty, which clears the stack by nullifying the reference to the top node, and topAndPop, which retrieves and removes the most recent element in a single operation.

The Reverse class demonstrates a practical application of stacks in reversing a sequence of data read from a file. The program reads a data file, parsing the sample rate and data points. Based on user input, it chooses either an array-based or linked list-based stack for storing data. By pushing data onto the stack as it reads, and then popping the data in reverse order, the program effectively inverts the original sequence. This technique is widely used in signal processing to reverse signals, in backtracking algorithms where the path must be retraced, and in undo functionalities within software applications.

The implementation of the Reverse class illustrates the importance of robust file handling, error management, and user input validation in software systems. It showcases how stacks serve as an essential tool for manipulating sequential data efficiently and reliably. Moreover, the adaptability of the stack, whether array-based or linked-list-based, highlights the importance of choosing the appropriate data structure based on the specific requirements of the task, such as memory constraints and performance considerations.

In conclusion, stack data structures are versatile and potent tools in computer science, underpinning many algorithms and systems. From their implementation details—ranging from arrays to linked lists—to their applications in reversing sequences and managing recursive processes, stacks demonstrate their critical role in enabling efficient computation. As technology advances, understanding these foundational structures remains essential for developing innovative and optimized solutions across various domains.

References

  • Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (3rd ed.). The MIT Press.
  • Knuth, D. E. (1998). The Art of Computer Programming, Volume 1: Fundamental Algorithms. Addison-Wesley.
  • Skiena, S. S. (2008). The Algorithm Design Manual (2nd ed.). Springer.
  • Dasgupta, S., Papadimitriou, C., & Vazirani, U. (2008). Algorithms. McGraw-Hill.
  • Hennessy, J. L., & Patterson, D. A. (2011). Computer Architecture: A Quantitative Approach (5th ed.). Morgan Kaufmann.