Question
Implement array-based PositionalList import java.util.Iterator; import net.datastructures.*; public class MyArrayPositionalList implements PositionalList { @Override public int size() { // TODO Auto-generated method stub return 0;
Implement array-based PositionalList
import java.util.Iterator;
import net.datastructures.*;
public class MyArrayPositionalList implements PositionalList {
@Override
public int size() {
// TODO Auto-generated method stub return 0;
}
@Override public boolean isEmpty() {
// TODO Auto-generated method stub
return false; }
@Override public Position first() {
// TODO Auto-generated method stub
return null; }
@Override public Position last() {
// TODO Auto-generated method stub
return null; }
@Override public Position before(Position p) throws IllegalArgumentException {
// TODO Auto-generated method stub
return null; }
@Override public Position after(Position p) throws IllegalArgumentException {
// TODO Auto-generated method stub
return null; }
@Override public Position addFirst(E e) {
// TODO Auto-generated method stub
return null; }
@Override public Position addLast(E e) {
// TODO Auto-generated method stub
return null; }
@Override public Position addBefore(Position p, E e) throws IllegalArgumentException {
// TODO Auto-generated method stub
return null; }
@Override public Position addAfter(Position p, E e) throws IllegalArgumentException {
// TODO Auto-generated method stub
return null; }
@Override public E set(Position p, E e) throws IllegalArgumentException {
// TODO Auto-generated method stub
return null; }
@Override public E remove(Position p) throws IllegalArgumentException {
// TODO Auto-generated method stub return null;
}
@Override public Iterator> iterator() {
// TODO Auto-generated method stub
return null; }
@Override public Iterable> positions() {
// TODO Auto-generated method stub
return null; }
}
Positional Class
import java.util.Iterator; public interface PositionalList extends Iterable { /** * Returns the number of elements in the list. * @return number of elements in the list */ int size(); /** * Tests whether the list is empty. * @return true if the list is empty, false otherwise */ boolean isEmpty(); /** * Returns the first Position in the list. * * @return the first Position in the list (or null, if empty) */ Position first(); /** * Returns the last Position in the list. * * @return the last Position in the list (or null, if empty) */ Position last(); /** * Returns the Position immediately before Position p. * @param p a Position of the list * @return the Position of the preceding element (or null, if p is first) * @throws IllegalArgumentException if p is not a valid position for this list */ Position before(Position p) throws IllegalArgumentException; /** * Returns the Position immediately after Position p. * @param p a Position of the list * @return the Position of the following element (or null, if p is last) * @throws IllegalArgumentException if p is not a valid position for this list */ Position after(Position p) throws IllegalArgumentException; /** * Inserts an element at the front of the list. * * @param e the new element * @return the Position representing the location of the new element */ Position addFirst(E e); /** * Inserts an element at the back of the list. * * @param e the new element * @return the Position representing the location of the new element */ Position addLast(E e); /** * Inserts an element immediately before the given Position. * * @param p the Position before which the insertion takes place * @param e the new element * @return the Position representing the location of the new element * @throws IllegalArgumentException if p is not a valid position for this list */ Position addBefore(Position p, E e) throws IllegalArgumentException; /** * Inserts an element immediately after the given Position. * * @param p the Position after which the insertion takes place * @param e the new element * @return the Position representing the location of the new element * @throws IllegalArgumentException if p is not a valid position for this list */ Position addAfter(Position p, E e) throws IllegalArgumentException; /** * Replaces the element stored at the given Position and returns the replaced element. * * @param p the Position of the element to be replaced * @param e the new element * @return the replaced element * @throws IllegalArgumentException if p is not a valid position for this list */ E set(Position p, E e) throws IllegalArgumentException; /** * Removes the element stored at the given Position and returns it. * The given position is invalidated as a result. * * @param p the Position of the element to be removed * @return the removed element * @throws IllegalArgumentException if p is not a valid position for this list */ E remove(Position p) throws IllegalArgumentException; /** * Returns an iterator of the elements stored in the list. * @return iterator of the list's elements */ Iterator iterator(); /** * Returns the positions of the list in iterable form from first to last. * @return iterable collection of the list's positions */ Iterable> positions(); }
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