Вы находитесь на странице: 1из 4

Lab13 Using STL Algorithms Second Part

==========================================
The existing project is going to use more algorithms from the
Standard Template Library, and also to access search, and
sort for both, standard C-type arrays and C++ arrays.
1. Inside the two files, use algorithm find(), with the return
type auto ptr, to search for the first-element in the array
that has a specified value.
Use if-else to display the index.
Select first a known value from the array, and next one not
part of the array.
2. Inside the two files, use algorithm count() to count how many
elements in the array have a specified value.
Change first the value at index 0 to become identical to the
value at index 1.
count() should return value 2.
3. Inside the two files, use algorithm count_if() to return the
number of elements with values greater than 50 (in
UsingCTypeAlgorithms()) and greater than 60 (in
UsingCppTypeAlgorithms()).
Insert the corresponding predicate-function-definitions at the
top of the two cpp functions.
4. Inside the two files, use algorithm is_sorted().
5. Inside the two files, use algorithm sort() to sort the array
in ascending order.
And display the array.
Follow with a call to is_sorted().

6. Inside the two files, use again the algorithm sort(), with
the third argument, greater<size_t>(), to reverse the current
sorted order to a descending order.
And display the array.
It requires #include <functional>
7. Inside the two files, use algorithm reverse(), to reverse the
current order, back to ascending.
And display the array.
8. Inside the two files, use algorithm binary_search().
The prerequisite is met: the array is sorted.
Select first a known value from the array, and next, one not
part of the array.
Implement code for function BinarySearch()
-----------------------------------------9. As a review, declare and implement, as part of the class
ProcessArray, the private function BinarySearch() (see
lecture-handout code example):
- implement it only for the C-type array;
- inside function UsingCTypeAlgorithms(), declare a particular
key value;
- call BinarySearch() and display the index;
- select first a known value from the array, and next, one not
part of the array.
10. Inside the two files, use algorithm random_shuffle().
And redisplay the arrays.
Implement code for function LinearSearchCArray()
------------------------------------------------11. Declare, as part of the class ProcessArray, the private
function LinearSearchCArray() (see lecture-handout example);

- implement it for the same C-type array;


- inside function UsingCTypeAlgorithms(), declare a particular
key value;
- call LinearSearchCArray() and display the index.
Implement code for function BubbleSortCArrayDescending()
-------------------------------------------------------12. Declare the function as private, void:
- implement it for cArray (see lecture-handout-example for
ascending order);
- call it and display the sorted array.
Implement code for function LinearSearchCppArray()
-------------------------------------------------13. Implement step 11 for the cpp array, calling the function
LinearSearchCppArray():
size_t element = LinearSearchCppArray(cppArray, key);
Select first a known value from the array, and next, one not
part of the array.
Implement code for function SelectionSortCppArray()
-------------------------------------------------14. Declare as private the function
void SelectionSortCppArray(array<size_t, SIZE> &)
- implement it to order the cpp-array in descending-order
(lecture-handout-example is for ascending-order);
- call it from UsingCppTypeAlgorithms() and
- display the sorted array.

15. Compile and run.


16. Update the Header at the top of the source-file.
17. Save All. Close solution.

********************************************
SEND TO INSTRUCTOR
- THE SOURCE/HEADER FILES
- THE FILE WITH CAPTURED OUTPUT-SCREEN
********************************************

Вам также может понравиться