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.
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;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.