Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ / FIXME ( 1 a ) : Implement the selection sort logic over bid.title / * * * Perform a selection sort on bid

// FIXME (1a): Implement the selection sort logic over bid.title
/**
* Perform a selection sort on bid title
* Average performance: O(n^2))
* Worst case performance O(n^2))
*
* @param bid address of the vector
* instance to be sorted
*/
void selectionSort(vector& bids){
//define min as int (index of the current minimum bid)
int i =0;
int j =0;
int indexSmallest =0;
int temp =0;
// check size of bids vector
// set size_t platform-neutral result equal to bid.size()
for (i =0; i < bids.size()-1; ++i){
indexSmallest = i;
for (j = i +1; j < bids.size(); ++j){
if (bids[j]< bids[indexSmallest]){
indexSmallest = j;
}
}
Bid temp = bids[i];
bids[i]= bids[indexSmallest];
bids[indexSmallest]= temp;
}
// pos is the position within bids that divides sorted/unsorted
// for size_t pos =0 and less than size -1
// set min = pos
// loop over remaining elements to the right of position
// if this element's title is less than minimum title
// this element becomes the minimum
// swap the current minimum with smaller one found
// swap is a built in vector method

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 And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

Why do mergers and acquisitions have such an impact on employees?

Answered: 1 week ago

Question

2. Describe the functions of communication

Answered: 1 week ago