Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

Define promotion.

Answered: 1 week ago

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

Discuss about training and development in India?

Answered: 1 week ago

Question

Explain the various techniques of training and development.

Answered: 1 week ago

Question

Explain the various techniques of Management Development.

Answered: 1 week ago