Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the append_to_list function so a book is inserted into an ordered list (by authors last name and first name) and the list remains ordered

Modify the append_to_list function so a book is inserted into an ordered list (by authors last name and first name) and the list remains ordered after the insertion. For example, a book by Ashley Spires should be before a book by Whee Winn in the list; a book by Elizabeth Spires should be after a book by Ashely Spires in the list. The order of the books does not matter if they have the same author.

struct book *append_to_list(struct book *list) { struct book *prev = NULL, *curr = list; struct book *new_ = NULL;

new_ = malloc(sizeof(struct book)); printf(" Enter title: "); read_line(new_->title,TITLE_LEN); printf("Enter author first name: "); read_line(new_->first,NAME_LEN); printf("Enter author last name: "); read_line(new_->last,NAME_LEN); new_->next = NULL; if (list == NULL) { printf("Enter price: "); scanf("%lf", &new_->price); printf("Enter number of requests: "); scanf("%d", &new_->num_requests); return new_; } while (curr != NULL) { if ((strcmp(new_->title, curr->title)== 0) &&(strcmp(new_->first, curr->first)==0) && (strcmp(new_->last, curr->last)==0)) { printf("book already exists. To update number of requests, enter operation code: u "); free(new_); return list; } else { prev = curr; curr = curr->next; } } printf("Enter price: "); scanf("%lf", &new_->price); printf("Enter number of requests: "); scanf("%d", &new_->num_requests); prev->next = new_; return list; }

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

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

1.Which are projected Teaching aids in advance learning system?

Answered: 1 week ago

Question

What are the classifications of Bank?

Answered: 1 week ago