Question
Translate this C function, splitList, into C# void splitList (contact *head, contact **h1, contact **h2) { *h1 = head; *h2 = NULL; contact *low =
Translate this C function, splitList, into C#
void splitList (contact *head, contact **h1, contact **h2) { *h1 = head; *h2 = NULL; contact *low = head; contact *high = head->next; // find where split will happen... while (high) { high = high->next; if (high==NULL) break; high = high->next; low = low->next; } //assign second half to h2 *h2 = low->next; // chop first half by setting next member to NULL low->next=NULL; } contact *mergeLists (contact *l1, contact*l2) { // setup our "control" variables contact *head = NULL; contact **lastRef = &head; while (1) // while TRUE... { if (l1==NULL || l2==NULL) { *lastRef = l1?l1:l2; break; } // do comparison here. if (strcmp(l1->lastName,l2->lastName)<=0) swapNodes(&l1,lastRef); else swapNodes(&l2,lastRef); // update last minor element reference lastRef = &((*lastRef)->next); } return head; } void swapNodes(contact **node1, contact **node2) { contact *src = *node1; *node1 = (*node1)->next; src->next = *node2; *node2 = src; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started