Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ Given the following struct to store information about books: struct Book string title; int year; }; And the following bubble sort code from class:

c++
image text in transcribed
Given the following struct to store information about books: struct Book string title; int year; \}; And the following bubble sort code from class: void bubblesort (int list [], int size) \{ bool swapped = false; do \{ for (int i=0;i list [i+1]){ Ifswap int temp = list[i]; list[i] = list[i+1] list[i+1] = temp; swapped = true; 3 ) 7 while (swapped == true); \} Rewrite the bubble sort function to do the following: A. Fix the bugl! B. Make it sort an array of Book-structs on the year field, in decreasing order (highest year (most recent) to lowest year). - Hint: you can use the assignment operator on an entire struct, you don't need to do it field by field (member by member). C. Make it output a count of how many times it compares (a field from) one array element to another. It should output the count only once. - Hint: do not count only when the comparison is true, but whenever the comparison is made (true or false)

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions