Question: Please write in C++ only CODE: // C++ program for implementation of selection sort #include using namespace std; void swap( int *xp, int *yp) {

Please write in C++ only

Please write in C++ only CODE: // C++ program for implementation of

CODE:

// C++ program for implementation of selection sort

#include

using namespace std;

void swap(int *xp, int *yp)

{

int temp = *xp;

*xp = *yp;

*yp = temp;

}

void selectionSort(int arr[], int n)

{

int i, j, min_idx;

// One by one move boundary of unsorted subarray

for (i = 0; i

// Find the minimum element in unsorted array

min_idx = i;

for (j = i+1; j

if (arr[j]

min_idx = j;

// Swap the found minimum element with the first element

swap(&arr[min_idx], &arr[i]);

}

}

/* Function to print an array */

void printArray(int arr[], int size)

{

int i;

for (i=0; i

cout

cout

}

// Driver program to test above functions

int main()

{

int arr[] = {64, 25, 12, 22, 11};

int n = sizeof(arr)/sizeof(arr[0]);

printArray(arr, n);

selectionSort(arr, n);

cout

printArray(arr, n);

return 0;

}

In some foreign country that uses lira as currency, given a certain amount of money in liras to spend and a number of items and their prices that can be purchased. Write a program to select items with the highest prices that can be purchased with the available money. For each item that is sold, the name and price are given. Note: this strategy does not guarantee that the items selected will have in total the highest possible value (for example, if we have 5$ and if the price of various items is 4,3 and 2$, select only the item of 4$, even though we could buy items of 3 and 2$ ). Input In the first line of the standard input there is the amount of money (real number) available and the number of item types N. Then N pairs of items with their price. N will not exceed 10. Output Print the item names and prices of purchased items (separated by a space) if any. The last line shows the remaining amount of money, if any. You may use arrays or vectors and any sort algorithm you choose

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!