Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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> implements ListADT {

protected class Node>{

private E data;

private Node next;

public Node(){

data = null;

next = null;

}

public Node(E item){

data = item;

next = null;

}

public Node(E item, Node n){

data = item;

next = n;

}

public void setNext(Node n){

next = n;

}

public Node getNext(){

return next;

}

public void setData(E item){

data = item;

}

public E getData(){

return data;

}

}

class ListIterator> implements Iterator {

// singly linked list used to store the contents of this list

private Node list;

private int count;

private int current;

public ListIterator(Node head, int c){

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 front = new 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 iterator() {

return new ListIterator(front.next, size);

}

public String toString(){

String str = "[";

Iterator iter = 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

1.The difference between climate and weather?

Answered: 1 week ago

Question

1. What is Fog ?

Answered: 1 week ago

Question

How water vapour forms ?

Answered: 1 week ago

Question

What is Entrepreneur?

Answered: 1 week ago

Question

Which period is known as the chalolithic age ?

Answered: 1 week ago

Question

LO3.2 Describe demand and explain how it can change.

Answered: 1 week ago

Question

LO3.3 Describe supply and explain how it can change.

Answered: 1 week ago