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

7. a function taking two simple integer lists as input and returning a list whic

ID: 3738149 • Letter: 7

Question

7. a function taking two simple integer lists as input and returning a list which is the union of the two input lists. You may assume that the lists are already sets. 8. a function which returns the reverse of a simple integer list. Solve it without using the built-in function. 9. a function which removes the first and last elements from an integer list and returns the resulting list in the reverse order. 10. a function which takes a simple list of numbers and sorts it in non-increasing order. 11. a function which outputs the maximum depth in a general integer ist.

Explanation / Answer

/*If you have any query do comment in the comment section else like the solution*/

list<int> Union(list<int> l1,list<int> l2)

{

set<int> s;

list<int> union

list<int>::iterator it1=l1.begin();

list<int>::iterator it2=l2.begin();

while(it1!=l1.begin())

{

s.insert(*it1);

it1++;

}

while(it2!=l2.begin())

{

s.insert(*it2);

it2++;

}

set<int>::iterator s1=s.begin();

while(s1!=s.end())

{

union.push_back(*s1);

s1++;

}

return union;

}

list<int> Reverse(list<int> l)

{

list<int> reverse;

list<int>::iterator it=l.begin();

while(it!=l.end())

{

reverse.push_front(*it);

it++;

}

return reverse;

}

list<int> removesFirstLast<list<int> l>

{

l.pop_front();

l.pop_back();

return l;

}

void sortNonIncreasingOrder(list<int> l)

{

sort(l.rbegin(),l.rend());

}

void maximumDepth(list<int> l)

{

int max=INT_MIN;

list<int>::iterator it=l.begin();

while(it!=l.end())

{

if(*it>max)

max=*it;

it++;

}

cout<<"Max depth: "<<max<<endl;

}

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