Question: / / 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!