Question: Write the following functions in C program, assuming the node type used is as follows: struct node { int data; struct node* next; }; and
Write the following functions in C program, assuming the node type used is as follows:
struct node
{
int data;
struct node* next;
};
and head is the head pointer of a list:
struct node* head;
a) Write a sortedMerge() function in C program that taking two lists, each of which is sorted in increasing order, and merges the two together into one list which is increasing order. This function should return a new list, which should be intertwining the nodes of the first two lists. You should consider various cases, e.g.
i. either 'a' or 'b' may be empty,
ii. during processing either 'a' or 'b' may run out first You should use the following function header:
struct node* sortedMerge(struct node* a, struct node* b) {
/* Your code... */
b) Write another function named reverse() which takes a list and reverses it by rearranging all the .next pointers and the head pointer. Ideally, this function should only make one pass of the list.
You should use the following function header:
/* This function takes a pointer (reference) to the head pointer. */ void Reverse(struct node** headRef) {
/* Your code... */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
