Question
Selection Sort on Parallel Vectors C++ PROGRAM: Suppose you went grocery shopping and you have a list of items that you purchased. You also have
Selection Sort on Parallel Vectors
C++ PROGRAM: Suppose you went grocery shopping and you have a list of items that you purchased. You also have another list that holds the prices of the items you purchased.
vectoritems {"pen", "paper", "milk", "cupcakes", "carrots", "salmon", "ice-cream", "butter", "sugar", "eggs"}; vector prices {6.49, 11.99, 3.19, 5.99, 1.49, 19.67, 4.59, 4.99, 3.49, 1.99};
The two vectors are parallel, that is, their positions are related to each other. For example, price of milk is 3.19 (subscript 2 of each vector).
Modify the Selection Sort algorithm to sort the items vector alphabetically and sort the prices vector along with it so the corresponding entries are still matching. This means that you are sorting and comparing the string vector alphabetically and mirroring the swap operations in the prices vector rather than just sorting them independently. For example, 3.19 corresponds to the price of "milk". So, if "milk" gets moved to a different position of the string vector, 3.19 should also get moved to the same position in its own vector. Read the program 8-7 on page 495 for a reference on how to sort vectors and 8-6 on page 491 for a reference on sorting parallel arrays.
When your program starts, call a function to show the two unsorted vectors. Call your parallel sorting function to sort the vectors. Then call your function to show the sorted vectors.
Add another parallel sort function to sort the vectors so that the prices vector is in ascending order. Call your new sorting function to sort the vectors. Then call your function to show the sorted vectors.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started