Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C program write a function( Node *merge_sorted_lists(Node *list 1, Node *list2) ) The output will looks like: You can optionally create the merge_sorted_lists function

Use C program write a function( Node *merge_sorted_lists(Node *list 1, Node *list2) )

image text in transcribed

image text in transcribed

image text in transcribed

The output will looks like:

image text in transcribed

You can optionally create the merge_sorted_lists function too for up to 10 bonus marks. This function should accept two sorted lists as input (sorted from lowest to highest values). The function should return a pointer to a list that has been created by merging and connecting the nodes in the two lists to form a new list that is also sorted from lowest to highest. The new list should contain all of the nodes that are in both lists, what should be different is how the nodes point to each other in order to form one merged list. #include #include #include #include typedef struct node { int value; struct node *next; } Node; void print_list(Node *head); Node* insert_at_head (Node *head, int new_value); Node *merge_sorted_lists(Node *listi, Node *list2); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 int main() { printf(" merge_sorted_lists test "); printf(" ** "); srand(time(NULL)); Node *list11 = NULL; Node *list12 = NULL; for (int i = 0; i value = new_value; new_node->next = NULL; if (head NULL) return new_node; else { new_node->next = head; return new_node; } == 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 void print_list(Node *head) { Node *current; current = head; int i = 0; while (current != NULL) { printf("Node %d: %d ", i, current->value); current = current->next; i++; } } merre_sorted_lists test List 11... Node 0:3 Node 1: 6 Node 2: 8 Node 3: 12 Node 4: 38 Node 5: 47 Node 6: 48 Node 7: 55 Node 8: 69 Node 9: 79 List 12... Node 0: 17 Node 1: 49 Node 2: 57 Node 3: 61 Node 4: 71 Node 5: 78 Node 6: 80 Node 7: 84 Node 8: 89 Node 9: 95 Merged list... Node 0: 3 Node 1: 6 Node 2: 8 Node 3: 12 Node 4: 17 Node 5: 38 Node 6: 47 Node 7: 48 Node 8: 49 Node 9: 55 Node 10: 57 Node 11: 61 Node 12: 69 Node 13: 71 Node 14: 78 Node 15: 79 Node 16: 80 Node 17: 84 Node 18: 89 Node 19: 95

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

Can you identify the kinds of risks that the business may face?

Answered: 1 week ago

Question

=+2 How can the effectiveness of global virtual teams be improved?

Answered: 1 week ago

Question

=+1 What are the major issues related to international T&D?

Answered: 1 week ago