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

The sample code SinglyLinkedList is a minimal implementation of a singly-linked

ID: 3644101 • Letter: T

Question

The sample code SinglyLinkedList is a minimal implementation of a singly-linked list. The element type is restricted to be a subtype of Comparable. Implement the following method in the SinglyLinkedList class:

// PRECONDITION: a and b are sorted in ascending order and contain no duplicates
// Returns true if every element of list 'c' also appears in list 'a'

public boolean checkContainsAll(SinglyLinkedList<E> a, SinglyLinkedList<E> c)

Let n = a.size() and m = c.size(). Your implementation should be O(n + m). (Note that without the precondition, this method would have to be O(nm). Note also that this should logically be a static method, but it is made nonstatic in order to have access to the inner class Node.)

Explanation / Answer

InsertNode(NODE **q,int num) { NODE *r,*temp ; temp = *q; r= malloc(sizeof(NODE)); r->data = num; //if it's fisrt node to be inserted if ( *q == NULL || num < (*q)->data) { *q = r ; (*q)->link=temp; } else { while(temp) { if ( (num > temp->data) && (num link->data ) ) { r->link = temp->link; temp->link = r; return; } temp = temp->link; } r->link = NULL; temp->link = r; } }
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