Question

Implement the Unsorted, sorted and indexed lists using Linked List base structure. (LLNode class under support...

Implement the Unsorted, sorted and indexed lists using Linked List base structure. (LLNode class under support package)

Files required:

1. ListInterface.java (given)
2. LLUnsortedList.java (implements ListInterface.java)
3. LLSortedList.java (extends LLUnsortedList.java, implements ListInterface.java)
4. LLIndexedList.java (implements LLIndexedListInterface.java, extends LLUnsortedList.java)

5. Driver

** Maybe create LLIndexedListInterface.java file too even though it is not required file!

I need the bolded Java Files (5) to be written separate  classes please! The interfaces can be implemented from below! Thank you

zip all your files and submit.

GIVEN FILES:

ListInterface.java

public interface ListInterface {

int size();

void add(T element);

boolean contains(T element); //Searching the item return true or false

//removes if exists, and return true

//false otherwise

boolean remove(T element);

//returns the element if exists,

//null otherwise

T get (T element);

//by putting toString method here,

//we require the implementation of it

String toString();

//current position is set to the first element

void reset();

T getNext();

}

----------------------------------------

LLNODE Class

public class LLNode{

//data members

private LLNode link;

private T info;

  

//constructors

public LLNode(T info){

this.info = info;

link = null;

}

//methods

public void setInfo(T info){

this.info = info;

}

public T getInfo(){

return info;

}

  public void setLink(LLNode link){

this.link = link;

}

public LLNode getLink(){

return link;

}

    public String toString() {

return info.toString();

}

}

If you can make a quick driver class that would be great too!

0 0
Add a comment Improve this question Transcribed image text
Answer #1


interface ListInterface<T> {

    int size();

    void add(T element);

    boolean contains(T element); // Searching the item return true or false
    
    // removes if exists, and return true
    // false otherwise
    boolean remove(T element);

    //returns the element if exists,
    //null otherwise
    T get(T element);

    //by putting toString method here,
    //we require the implementation of it
    String toString();

    //current position is set to the first element
    void reset();

    T getNext();
}

class LLNode<T> {

    // data members
    private LLNode<T> link;
    private T info;

    // constructors
    public LLNode(T info) {
        this.info = info;
        link = null;
    }

    // methods

    public void setInfo(T info) {
        this.info = info;
    }

    public T getInfo() {
        return info;
    }

    public void setLink(LLNode<T> link) {
        this.link = link;
    }

    public LLNode<T> getLink() {
        return link;
    }

    public String toString() {
        return info.toString();
    }
}

class LLUnsortedList<T> implements ListInterface<T> {
    // Do not add new instance variables or modify existing ones.
    private LLNode<T> head, current;
    private int size;

    @Override
    public void add(T data) {
        // error conditions
        if (data == null) {
            throw new IllegalArgumentException("Invalid data");
        }

        // create a node
        LLNode<T> node = new LLNode<T>(data);
        if(head == null) {
            head = node;
            current = head;
        } else {
            // find the node, after which this new node need to be inserted
            LLNode<T> prev = head;
            while (prev.getLink() != null) {
                prev = prev.getLink();
            }
            prev.setLink(node);
        }

        size++;
    }

    public T get(T element) {
        LLNode<T> x = head;
        while (x != null) {
            if(x.getInfo().equals(element)) {
                return x.getInfo();
            }
            x = x.getLink();
        }
        return null;
    }
    public boolean remove(T element) {
        if(head == null) {
            return false;
        }
        if(head.getInfo().equals(element)) {
            head = head.getLink();
            size--;
            return true;
        }
        
        LLNode<T> prev = head;
        while (prev.getLink() != null) {
            if(prev.getLink().getInfo().equals(element)) {
                prev.setLink(prev.getLink().getLink());
                size--;
                return true;
            }
            prev = prev.getLink();
        }
        return false;
    }

    @Override
    public int size() {
        return size;
    }
    
    public T getNext() {
        if(current == null) {
            return null;
        }
        T x = current.getInfo();
        current = current.getLink();
        return x;
    }
    @Override
    public String toString() {
        String output = "";
        
        LLNode<T> curr = head;
        while(curr != null) {
            output += curr.getInfo() + " ";
            curr = curr.getLink();
        }
        
        return output.trim();
    }

    @Override
    public boolean contains(T element) {
        return get(element) != null;
    }

    @Override
    public void reset() {
        current = head;
    }
}

**************************************************

Answering your first question, as the questions are completely unrelated and require different code. I request you to please post single question in a thread, so that it helps us in explaining the things better to you. Hope you understand!

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
Implement the Unsorted, sorted and indexed lists using Linked List base structure. (LLNode class under support...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a recursive method remove(int target, LLNode list) that removes all occurrences of target from list...

    Write a recursive method remove(int target, LLNode list) that removes all occurrences of target from list and returns a reference to the new list. For our example list the statement values = remove(6, values); would result in values referencing the list containing 3 9 12 15 18 19 19 and 20. If target is not contained in list then the list remains unchanged. Please also add a driver class to demonstrate that the method is working correctly. LLNode.java //---------------------------------------------------------------------------- //...

  • In Java: Assume the "ferrets" variable points to a linked list of "LLNode." Write code that...

    In Java: Assume the "ferrets" variable points to a linked list of "LLNode." Write code that traverses the list and prints the following. Do not forget to consider the case where the list is empty. The "LLNode" class is given: public class LLNode { protected T info; protected LLNode link; public LLNode(T info) { this.info = info; link = null; } public void setInfo(T info) { this.info = info; } public T getInfo() { return info; } public void setLink(LLNode...

  • Use the following implementation of LinkedListNode to write the Stack4T> classi public class LinkListNodecT>T private T...

    Use the following implementation of LinkedListNode to write the Stack4T> classi public class LinkListNodecT>T private T info; private LinkListNode link; public LinkListNode ( T info) this, info = info; link = null; public T getInfo() return info; public LinkListNode getlink() return link; public void setInfo( T info) this.infoinfo; public void setLink (LinklistNode link) this.link = link; public interface StackInterface <T T top() throws StackUnderflowException; void pop () throws StackUnderflowException; void push (T element);

  • public class CharNode{ private CharNode link; private char info; public CharNode(char info) { this.info = info;...

    public class CharNode{ private CharNode link; private char info; public CharNode(char info) { this.info = info; this.link = null; } public CharNode(char c, CharNode link) { this.info = info; this.link = link; } public CharNode getLink() { return link; } public void setLink(CharNode link) { this.link = link; } public char getInfo() { return info; } public void setInfo(char info) { this.info = info; } } //Remember Queue is a first-in-first-out data structure public class CharQueue { // front is...

  • Using a doubly linked list as the underlying data structure, implement a list ADT that implements...

    Using a doubly linked list as the underlying data structure, implement a list ADT that implements the ListInterface.java found in the ProgProjTwo Eclipse project starting point for this assignment. In addition to the forward iterator defined by resetIterator( ) and getNextItem( ) in ListInterface.java, implement a backwards iterator by providing resetBackIterator( ) and getPreviousItem( ) methods. As noted in the syllabus addendum, you are encouraged to develop a find( ) helper method that can support various list ADT operations. A...

  • Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info...

    Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data type: QueueNode<T> Constructors: Name: QueueNode Access modifier: public Parameters: info (data type T) Task: sets the value of this.info to the value of the info parameter sets the value of link to null Methods Name: setInfo Access modifier: public Parameters: info (data type T) Return type: void Task: sets the...

  • use intellij idea main java Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier:...

    use intellij idea main java Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data type: Queue Node<T> Constructors: Name: QueueNode Access modifier: public Parameters: info (data type T Task: sets the value of this.info to the value of the info parameter sets the value of link to null Methods Name: link Access modifier: private Data type: QueueNode<T> Constructors: Name:...

  • Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access...

    Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data...

  • Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access...

    Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data...

  • use intellij idea main java wp the professor. Please make sure to only implement what is...

    use intellij idea main java wp the professor. Please make sure to only implement what is asked for. You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here. Step 1 Develop the following interface: Interface Name: Queue Interface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT