Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an ordered linked list in java: As for the style and documentation, pleas

ID: 3854758 • Letter: C

Question

Create an ordered linked list in java:

As for the style and documentation, please don't return or break from inside a loop. Also, please add lots of comments so that I know what you're doing.

Package name should be "assign6"

ui class name File to submit: Ordered LinkedList.java OrderedLinkedList list: node - count: int + OrderedLinkedList0 + numEntries0: int + insert (int): void + delete (int): void* + toString0: String + get(int): int * Throws exception Required methods 1. OrderedList 0 2. numEntries0:int 3. insert (int): void a. create an empty linked list of integers a. return the number of integers currently stored in the list a. b. insert an integer into the list so that the elements are in ascending order do not allow for duplicates in the array 4. delete (int): void find the integer in the list and remove it if the value is not in the array, throw an exception with the string containing the number that could not be deleted and the message “Delete not successful" if the value is in the array, remove it so that the elements remain in ascending order a. b. c. 5. toString0: String return the values in the array so that all values are separated by a space the string should be “1 2 3" not" 1 2 3 “ an empty list should return an empty string (0 characters) a. b, c. 6. get(int): int a. b. find the integer in the list at the position indicated and return it if the value is not in the list, throw an exception with the string containing the number of the position and the message "Get not successful" the position of the nodes starts at 0, not 1 c.

Explanation / Answer

package assign6;

/**
*
* @author Sam
*/
public class OrderedLinkList {
    private class IntNode {
        public int info;
        public IntNode next;

        public IntNode(int info, IntNode next) {
            this.info = info;
            this.next = next;
        }
    }
    private IntNode list;
    private int count;

    public OrderedLinkList() {
        list = null;
        count = 0;
    }
  
    public int numEntries(){
        return count;
    }
  
    public void insert(int info) {
        if (list == null){
            list = new IntNode(info, null);
            return;
        }
        if (list.info > info) {
            list = new IntNode(info, list);
            return;
        }
      
        IntNode tmp = list;
        while (tmp.next != null){
            if (tmp.next.info > info)
                break;
            tmp = tmp.next;
        }
      
        tmp.next = new IntNode(info, tmp.next);
    }
  
    public void delete(int info){
        if (list == null) {
            throw new NullPointerException("Delete not successful");
        }
        if (list.info == info) {
            list = list.next;
            return;
        }
        IntNode tmp = list;
        while (tmp.next != null){
            if (tmp.next.info == info) {
                tmp.next = tmp.next.next;
                return;
            }
            tmp = tmp.next;
        }
        throw new IllegalArgumentException("Delete not successful");
    }
  
    public int get(int index) {
        if (index >= count)
            throw new IndexOutOfBoundsException("Count: " + count+ ". Get not Successful");
        IntNode tmp = list;
        for (int i = 0; i<index; i++)
            tmp = tmp.next;
        return tmp.info;
    }

    @Override
    public String toString() {
        String out = "";
        if (list == null)
            return out;
        IntNode tmp = list;
        while (tmp.next != null) {
            out += tmp.info + " ";
            tmp = tmp.next;
        }
        out += tmp.info;
        return out;
    }
}


I hope this helps. Please let me know if you need any modifications

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote