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

Write an algorithm to add a new node Write an algorithm to add a new node in asc

ID: 672173 • Letter: W

Question

Write an algorithm to add a new node Write an algorithm to add a new node in ascending lexicographic order by name to a singly linked list. If two or more nodes contain the same name, order the nodes containing the same value for name in ascending lexicographic order by age. A sample list spprars below. Your algorithm must cover every possible case. Assume the list is We are evaluating the garbage collection algorithms for three programming languages L1 satisfies memory request by sequentially allocating memory from the till memory is exhausted. When memory is exhausted, it halts the program in execution compact at the top forming a hole allowing execution to resume like Java/Python Languages L2 and L3 allow programmers to request It is the programmers responsibility however to reclaim e two different types of objects with different space requirements All Language L3 places blocks c The same type on separate available storage list. Returned memory is used prior to allocating new memory from the heap in both languages L2 and L3. New memory is

Explanation / Answer

Here is the algorithm to insert new node sorted in lexagraphic order

void InsertNewNodeSort(struct node** headReference, struct node* newNode)
{
struct node* curr;
/* Checking for head..if list empty..then place it as a head */
if (*headReference == NULL || (*headReference)->data >= newNode->data)
{
newNode->next = *headReference;
*headReference = newNode;
}
else
{
/* Just searching where to insert this new node*/
curr = *headReference;
while (curr->next!=NULL && curr->next->data < newNode->data)
{
curr = curr->next; /*Once found place just before them*/
}
/*Making present new node next node as above calsulated node*/
newNode->next = curr->next;
curr->next = newNode;
}
}

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