Must be written in c++:
This
problem solely involves your demonstration of the proper usage of
C++ STL
std::list<int>
Below you will be given four total functions to develop (two are listed here, two separately after)
(1) The first function you will need to implement is the main() function of course
(2) The second function you will need to implement is one which prints all elements of a list collection
You are free to create your own test data as you see fit, however these linked lists of integers represent test cases for all possible functions to develop:
// C++ Code:-
#include<bits/stdc++.h>
using namespace std;
// Function to prints all elements of a list collection
with space seperated.
void PrintAllElementsOfList(const std::list<int> &
list)
{
for(auto it=list.begin(); it!=list.end();++it)
cout<<*it<<" ";
cout<<endl;
}
// main function to check the implementation of all
other function
int main()
{
// Declaring some list given in question
list<int> a{ 1, 3, 5, 7, 9, 11, 13, 15 };
list<int> b{ 2, 4, 6, 8, 10, 12, 14, 16 };
list<int> c{ 1, 2, 2, 3, 4, 4, 5, 6, 6 };
list<int> d{ 1, 4, 5, 8, 9 };
list<int> e{ 9, 5, 4, 3, 3, 4, 5, 9 };
list<int> f{ 1, 1, 2, 2, 3, 3, 4, 4 };
list<int> g{ 1, 2, 3, 4, 5 };
// Printing the elements of all list by calling
PrintAllElementsOfList function
// One by one
cout<<"List 1: ";
PrintAllElementsOfList(a);
cout<<"List 2: ";
PrintAllElementsOfList(b);
cout<<"List 3: ";
PrintAllElementsOfList(c);
cout<<"List 4: ";
PrintAllElementsOfList(d);
cout<<"List 5: ";
PrintAllElementsOfList(e);
cout<<"List 6: ";
PrintAllElementsOfList(f);
cout<<"List 7: ";
PrintAllElementsOfList(g);
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.