Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I just need help with this method, thank you in advance ! // Q2 : sort (10 points) // This function is used to sort
I just need help with this method, thank you in advance !
// Q2 : sort (10 points) // This function is used to sort the list(array of structs) numerically by book ID. // Parse the list and compare the book IDs to check which one should appear before the other in the list. // Sorting should happen within the list. That is, you should not create a new array of structs having sorted books. [// Hint: Use a temp struct (already declared) if you need to swap two structs in your logic // the number of books currently stored in the list (initialized to 0) int count = 0; unsigned int bookId; void sort() { struct libraryRecord libraryTemp; // Enter code here // needed for swapping structs. Not absolutely necessary to use. // display message for user to check the result of sorting. printf(" Book list sorted! Use display option 'd' to view sorted list. "); Enter your selection: a: add a new book d: display book list r: remove a book from list s: sort book list by ID q: quit S Book list sorted! Use display option 'd' to view sorted list. Enter your selection: a: add a new book d: display book list r: remove a book from list s: sort book list by ID q: quit d Book Title: Sapiens Author Name: Yuval Book Type: Nonfiction Book ID: 1 Aisle number: 1 Book Title: The Alchemist Author Name: Paulo Book Type: Fiction Book ID: 2 Aisle number: 2 Book Title: A Promised Land Author Name: Barack Obama Book Type: Nonfiction Book ID: 3 Aisle number: 3 // Q2 : sort (10 points) // This function is used to sort the list(array of structs) numerically by book ID. // Parse the list and compare the book IDs to check which one should appear before the other in the list. // Sorting should happen within the list. That is, you should not create a new array of structs having sorted books. [// Hint: Use a temp struct (already declared) if you need to swap two structs in your logic // the number of books currently stored in the list (initialized to 0) int count = 0; unsigned int bookId; void sort() { struct libraryRecord libraryTemp; // Enter code here // needed for swapping structs. Not absolutely necessary to use. // display message for user to check the result of sorting. printf(" Book list sorted! Use display option 'd' to view sorted list. "); Enter your selection: a: add a new book d: display book list r: remove a book from list s: sort book list by ID q: quit S Book list sorted! Use display option 'd' to view sorted list. Enter your selection: a: add a new book d: display book list r: remove a book from list s: sort book list by ID q: quit d Book Title: Sapiens Author Name: Yuval Book Type: Nonfiction Book ID: 1 Aisle number: 1 Book Title: The Alchemist Author Name: Paulo Book Type: Fiction Book ID: 2 Aisle number: 2 Book Title: A Promised Land Author Name: Barack Obama Book Type: Nonfiction Book ID: 3 Aisle number: 3Step 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