🔖 Background Information
N/A
🎯 Problem Statement
The goal of this lab is to explore the C++ std::sort function with a variety of arguments. You will test out how built-in C++ functions, custom lambda functions, and custom structs affect the output.
✅ Acceptance Criteria
- Create an array of ten integers that are initially in a scrambled order.
- Run
std::sorton the array with the following passed in as the third argument:- No third argument
- The
greaterandlessfunctions built into C++ - A lambda comparing two integer arguments with cases for greater than and less than
- A custom struct comparing two integer arguments with cases for greater than and less than
- You will submit the following:
- Your C++ script which includes the array and the different sorts.
- Answers to the Thought-Provoking Questions.
📋 Dev Notes
- You might need to rescramble the integers after every test to make sure you are not skewing the output in any way.
- You do NOT need to write unit tests for this lab.
🖥️ Example Output
You need to test std::sort for a variety of cases listed above. Note that you might need to rescramble the array or only test one sort at a time to ensure that the results of one trial do not skew the results of another.
Your driver program might include:
#include <array>
int main()
{
std::array<int, 10> my_numbers{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
// Sort the numbers using the default sort function
std::sort(my_numbers.begin(), my_numbers.end());
// Sort the numbers using the std::greater function
std::sort(my_numbers.begin(), my_numbers.end(), std::greater<int>());
// Repeat the process above for each of the functions in question
// E.g. std::less, a lambda, a struct, etc.
}📝 Thought Provoking Questions
For each of the cases listed in the acceptance criteria, answer the following questions:
- What does the expression return when you print it out to the console?
- Does the expression change the original array?
💼 Add-Ons For the Portfolio
N/A
🔗 Useful Links
N/A
📘 Works Cited
N/A