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

The following exercise deal with coding a LinkedList. - The methids you are writ

ID: 3755381 • Letter: T

Question

The following exercise deal with coding a LinkedList.
- The methids you are writing are instance methods inside of LinkedList, so you can use the Node class.
- The LinkedList contains a Node<E> head and tail(optional).
- The LinkedList contains a method size() that returns the number of elements in the list.
- The Node objects are singly-linked, and contain public variable next, which references the next node in the list.
- you can use an Iterator if you want but you dont need to.

12. (15 points) Suppose we had a new type of LinkedList, called the SortedLinkedList, which is a linked list, but it keeps all the items in the list sorted. As a result, when we add an item to a SortedLinkedList, we don't provide an index, as the SortedLinkedList figures out where to put , the new item based on the values already in the list. Your task is is to complete the add method for a SortedLinkedList, shown below. This method inserts a new item into the SortedLinkedList in such a way that the list remains sorted. For example, if the list is [1,25] and we call add (4), the becomes [1.2.43]. For simplicity: . You can use either a singly or doubly linked list. . you can use , and =_ to compare items, but if you remember how to use compareTo(), you can do so for extra credit. . You may not call the add(int index , E item) method. . You may not call the getNode() method (although you may rewrite it), public void add(E item)f

Explanation / Answer

please go thew the function.

public void add(E item) {
        struct SortedLinkedList * temp = head;
        int pos = 0;
        if(temp->number > item->number)
        {
                item->next = temp;
                temp = item;
        }
        else
        {
                while(temp != NULL)
                {
                        if(temp->next->number < item->number)
                        {
                                item->next = temp->next;
                                temp->next = item;
                                break;
                        }
                        pos++;
                        temp = temp->next;

                }

        }

}

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