Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3.Demonstrate the utilization of the following STL list operations (IN C++): a.

ID: 3668887 • Letter: 3

Question

3.Demonstrate the utilization of the following STL list operations (IN C++):

a. merge (lst): - The merge method in the list<> STL. Merge the current list, which is assumed to be sorted, with the argument lst, also assumed to be sorted. Print the sorted list.

b. find_if ():-returns the iterator to the element that satisfy the predicate condition. Create your own predicate function

c. reverse():-reverse order of elements

d. sort() :-place values into sorted order

e. remove_copy():-Remove copies of elements divisible by 4 from the a vector container.

Explanation / Answer

b.

c.

d.

e.

  #include <iostream>     // std::cout  #include <algorithm>    // std::sort  #include <vector>       // std::vector    bool myfunction (int i,int j) { return (i<j); }    struct myclass {    bool operator() (int i,int j) { return (i<j);}  } myobject;    int main () {    int myints[] = {32,71,12,45,26,80,53,33};    std::vector<int> myvector (myints, myints+8);               // 32 71 12 45 26 80 53 33      // using default comparison (operator <):    std::sort (myvector.begin(), myvector.begin()+4);           //(12 32 45 71)26 80 53 33      // using function as comp    std::sort (myvector.begin()+4, myvector.end(), myfunction); // 12 32 45 71(26 33 53 80)      // using object as comp    std::sort (myvector.begin(), myvector.end(), myobject);     //(12 26 32 33 45 53 71 80)      // print out content:    std::cout << "myvector contains:";    for (std::vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)      std::cout << ' ' << *it;    std::cout << ' ';      return 0;  }  
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote