The goal is to implement a Stack data structure using an array to store elements according to the StackADT interface. The ArrayStack class defines fields for the index of the top element and a generic array buffer. It must include JavaDoc and pass tests to be graded.
dusjagr & nano talk on open tools for agriculture research and learning
1 The goal is to implement DataStructuresArrayStack accor.pdf
1. (1) The goal is to implement DataStructures.ArrayStack according to the interface ADTs.StackADT
********************************************
package DataStructures;
import ADTs.StackADT;
import Exceptions.EmptyCollectionException;
import Exceptions.StackOverflowException;
public class ArrayStack<T> implements StackADT<T> {
/** The index of where the top of the stack is */
int top;
/** The array that holds the stack */
T[] buffer;
public ArrayStack() {
}
public ArrayStack(int initialCapacity) {
}
}
*******************************************************
package ADTs;
import Exceptions.EmptyCollectionException;
import Exceptions.StackOverflowException;
/**
* An interface for a Stack
* Specific stack implementations will implement this interface
* For use Data Structures & Algorithms
*
*
* author unknown
*/
public interface StackADT<T> extends CollectionADT<T> {
/**
* Adds the specified element to the top of the stack
*
* @param element element to be pushed onto the stack
*/
public void push(T element) throws StackOverflowException;
/**
* Removes and returns the element that is on top of the stack
*
* @return the element removed from the stack
* @throws EmptyCollectionException
*/
public T pop() throws EmptyCollectionException;
2. /**
* Returns (without removing) the element that is on top of the stack
*
* @return the element on top of the stack
* @throws EmptyCollectionException
*/
public T peek() throws EmptyCollectionException;
}
*****************************************
package ADTs;
import Exceptions.*;
/**
* An interface for an ordered (NOT SORTED) List
* Elements stay in the order they are put in to the list
* For use in Data Structures & Algorithms
*
*
* @author unknown
*/
public interface ListADT<T> extends CollectionADT<T> {
/**
* Adds the specified element to the list at the front
*
* @param element: the element to be added
*
*/
public void addFirst(T element);
/**
* Adds the specified element to the end of the list
*
* @param element: the element to be added
*/
public void addLast(T element);
/**
* Adds the specified element to the list after the existing element
*
* @param existing: the element that is in the list already
* @param element: the element to be added
* @throws ElementNotFoundException if existing isn't in the list
*/
public void addAfter(T existing, T element) throws ElementNotFoundException,
EmptyCollectionException;
3. /**
* Removes and returns the specified element
*
* @return the element specified
* @throws EmptyCollectionException
* @throws ElementNotFoundException
*/
public T remove(T element) throws EmptyCollectionException, ElementNotFoundException;
/**
* Removes and returns the first element
*
* @return the first element in the list
* @throws EmptyCollectionException
*/
public T removeFirst() throws EmptyCollectionException;
/**
* Removes and returns the last element
*
* @return the last element in the list
* @throws EmptyCollectionException
*/
public T removeLast() throws EmptyCollectionException;
/**
* Returns (without removing) the first element in the list
*
* @return element at the beginning of the list
* @throws EmptyCollectionException
*/
public T first() throws EmptyCollectionException;
/**
* Returns (without removing) the last element in the list
*
* @return element at the end of the list
* @throws EmptyCollectionException
*/
public T last() throws EmptyCollectionException;
/**
* Return whether the list contains the given element.
*
* @param element
* @return
* @throws EmptyCollectionException
4. */
public boolean contains(T element) throws EmptyCollectionException;
/**
* Returns the index of the given element.
*
* @param element
* @return the index of the element, or -1 if not found
*/
public int indexOf(T element);
/**
* Return the element at the given index of a list.
*
* @param element
* @return
* @throws EmptyCollectionException
*/
public T get(int index) throws EmptyCollectionException, InvalidArgumentException;
/**
* Set the at the given index of a list.
*
* @param element
* @return
* @throws EmptyCollectionException
*/
public void set(int index, T element) throws EmptyCollectionException, InvalidArgumentException;
}
***********************************************
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ADTs;
/**
* An interface for an AbstractDataType
* Specific ADT interfaces will extend this
* For use in Data Structures & Algorithms
*
*
* @author unknown
*/
public interface CollectionADT<T> {
5. /**
* Returns true if the collection contains no elements
*
* @return true if the collection is empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in the collection
*
* @return the number of elements as an int
*/
public int size();
/**
* Returns a string representation of the collection
*
* @return a string representation of the collection
*/
@Override
public String toString();
}
**********************************
Project must compile (otherwise no grade)
(1) JavaDoc for DataStructures.ArrayStack class
(2) Tests passing for DataStructures.ArrayStack class