Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(b) The very, very buggy code below is intended to merge, in place, two sorted, linked lists into a single sorted, linked list: it is

image text in transcribed
(b) The very, very buggy code below is intended to merge, in place, two sorted, linked lists into a single sorted, linked list: it is supposed to take two lists as input and destructively modify them so that at the end, they form a single, sorted, linked list in memory. Find as many potential bugs in the code as you can: typedef struct link { char *data; struct link *next; } list; list *merge (list *input1, list #input 2) { list *output - NULL, *tail, *next; do { if(strcmp(input1->data, input 2->data) next; } else { next - input2; input2 - input 2->next; if (output = NULL) { output - tail - next; } else { tail->next = next; tail - tail->next; } while (input1 != NULL && input2 != NULL); if (input1 != NULL) tail->next = input1; else tail->next - input2; return output; (b) The very, very buggy code below is intended to merge, in place, two sorted, linked lists into a single sorted, linked list: it is supposed to take two lists as input and destructively modify them so that at the end, they form a single, sorted, linked list in memory. Find as many potential bugs in the code as you can: typedef struct link { char *data; struct link *next; } list; list *merge (list *input1, list #input 2) { list *output - NULL, *tail, *next; do { if(strcmp(input1->data, input 2->data) next; } else { next - input2; input2 - input 2->next; if (output = NULL) { output - tail - next; } else { tail->next = next; tail - tail->next; } while (input1 != NULL && input2 != NULL); if (input1 != NULL) tail->next = input1; else tail->next - input2; return output

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

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions