Question
HAVING TROUBLE WITH FIRST, LAST, REMOVE AT POSITION, REMOVE FIRST, REMOVE LAST , SET , SET here is the code i have so far (java)
HAVING TROUBLE WITH FIRST, LAST, REMOVE AT POSITION, REMOVE FIRST, REMOVE LAST , SET , SET
here is the code i have so far (java)
public abstract class List
protected class Node
private E data;
private Node
public Node(){
data = null;
next = null;
}
public Node(E item){
data = item;
next = null;
}
public Node(E item, Node
data = item;
next = n;
}
public void setNext(Node
next = n;
}
public Node
return next;
}
public void setData(E item){
data = item;
}
public E getData(){
return data;
}
}
class ListIterator
// singly linked list used to store the contents of this list
private Node
private int count;
private int current;
public ListIterator(Node
list = head;
count = c;
current = 0;
}
public boolean hasNext() {
return current < count;
}
public E next() {
if(!hasNext()) throw new NoSuchElementException();
E data = list.data;
list = list.next;
current++;
return data;
}
public void remove() {
// to do (does nothing, add code if you need to delete while traversing)
}
}
protected Node
protected int size;
@Override
abstract public void add(T item);
@Override
public T first() throws ListEmptyException {
//TO DO
}
@Override
public T last() throws ListEmptyException {
// TODO
}
}
@Override
public T removeFirst() throws ListEmptyException {
// TODO
}
@Override
public T removeLast() throws ListEmptyException {
// TODO
}
@Override
public T removeAtPosition(int location) throws IndexOutOfBoundsException {
// TODO
}
@Override
abstract public void remove(T item);
@Override
public void set(T item1, T item2) throws ListEmptyException {
// TODO
}
}
@Override
public T set(T item, int location) throws IndexOutOfBoundsException {
// TODO
returnnull;
}
}
@Override
abstract public int search(T item);
@Override
public boolean contains(T item) throws ListEmptyException {
if(isEmpty())
throw new ListEmptyException();
return search(item) != -1;
}
@Override
public boolean isEmpty() {
return size == 0;
}
@Override
public int getSize(){
return size;
}
@Override
public void clear() {
size = 0;
front.setNext(null);
System.gc();
}
@Override
public Iterator
return new ListIterator
}
public String toString(){
String str = "[";
Iterator
while(iter.hasNext())
str += iter.next() + (iter.hasNext() ? ", " : "]"); //condtion do if true or do if false
return str;
}
}
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