Start on the linked list solution

This is the start of the linked list solution.



public class OurLinkedList<E> implements OurList<E> {
    private Node first;
    private int size;

    @Override
    public boolean isEmpty() {

        return (first == null);

    }

    @Override
    public int size() {
        return size;

    }

    @Override
    public void add(int index, E item) throws ListIndexOutOfBoundsException {
        if (index < 0 || index > size) {
            throw new ListIndexOutOfBoundsException("Index " + index + " is out of bounds. Size = " + size);
        }
        size++;
        if (index == 0) {
            first = new Node(item, first);
        }

    }

    @Override
    public E get(int index) throws ListIndexOutOfBoundsException {
        // TODO Auto-generated method stub
 

        return null;

    }

    @Override
    public void remove(int index) throws ListIndexOutOfBoundsException {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException();
       
    }

    @Override
    public void clear() {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException();

    }
    
    private class Node {
        E item;
        Node next;
        
        public Node(E item, Node next){
            this.item = item;
            this.next = next;
        }
    }

}

CSci 2101 course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.