Question: C++ STL Iterators and ALgorithms half of code given , extend the rest #include #include #include #include #include #include using namespace std; int main(){ cout

C++ STL Iterators and ALgorithms

half of code given , extend the rest

#include

#include

#include

#include

#include

#include

using namespace std;

int main(){

cout << "---------------------- STL vector ---------------------- ";

// declare container here

vector vec;

cout << "Enter numbers to store in STL containers (enter a letter to stop) ";

// read in integers from STDIN here and store them in the vector

while(true)

{

int n;

if(cin>>n)

vec.push_back(n);

else

break;

}

cout << "There are " <

// print out the contents of the container in the reverse order that they were read in

for(vector::reverse_iterator it = vec.rbegin(); it != vec.rend(); ++it)

{

cout << *it <

}

cout << "---------------------- STL list ---------------------- ";

// declare container here

list lt;

// copy elements from the vector into this container (in the order that they were entered)

lt.assign(vec.begin(),vec.end());

cout << "There are " <

// print out the contents of the container in the reverse order that they were read in

// Hint: Make a copy of the elements into a second list first . . .

for(list::reverse_iterator it = lt.rbegin(); it != lt.rend(); ++it)

{

cout << *it <

}

cout << "---------------------- STL deque ---------------------- ";

// declare container here

deque dq;

// copy elements from the vector into this container (in the order that they were entered)

dq.assign(vec.begin(),vec.end());

cout << "There are " << dq.size() << " integers in the deque" << endl;

// print out the contents of the container in the reverse order that they were read in

for(deque::reverse_iterator it = dq.rbegin(); it != dq.rend(); ++it)

{

cout << *it <

}

cout << "---------------------- STL stack ---------------------- ";

// declare container here

stack st;

// Optionally, for a challenge, specify the underlying container (and it's type) when declaring the stack container (and it's type)

// copy elements from the vector into this container (in the order that they were entered)

for(vector::iterator it=vec.begin();it!=vec.end();++it)

st.push(*it);

cout << "There are " <

// print out the contents of the container in the reverse order that they were read in

while(st.empty()== false)

{

cout<

st.pop();

}

cout << "---------------------- STL queue ---------------------- ";

// declare container here

queue que;

// copy elements from the vector into this container (in the order that they were entered)

for(vector::iterator it=vec.begin();it!=vec.end();++it)

que.push(*it);

cout << "There are " <

// print out the contents of the container in the reverse order that they were read in

// Hint: For each element, make a temporary queue with all of the remaining elements in it . . .

stack temp;

while(que.empty()==false)

{

temp.push(que.front());//copy to another container

que.pop();

}

//print that temporary container data

while(temp.empty()== false)

{

cout<

temp.pop();

}

cout << "---------------------- STL priority_queue ---------------------- ";

// declare container here

// copy elements from the vector into this container (in the order that they were entered)

priority_queue pq(vec.begin(),vec.end());

cout << "There are " <

cout << "Priority queues do not keep track of the insertion order of their contents, but here's it's contents: ";

// print out the contents of the container

// print out the contents of the container in the reverse order that they were read in

while(!pq.empty()) {

cout << pq.top() <

pq.pop();

}

cout << " Can the number of elements and the contents is printed out in the order that they were entered for associative containers? Why? ";

/*

* Answer the question here with a cout statement

*/

cout<<" containers are used for different purpose. Depends on use of container and size of container are needed by programmer. ";

return 0;

}

/ * now add to that code , fix below so it will compile and also do the task it ask for each cout */

cout << " ---------------------- Printing out the contents in the ordered entered using iterators ---------------------- "; cout << "---------------------- STL vector ---------------------- "; // use STL vector iterators to print out the values stored in the container if possible (otherwise print out why it's not possible) cout << "---------------------- STL array ---------------------- "; // use STL array iterators to print out the values stored in the container if possible (otherwise print out why it's not possible) cout << "---------------------- STL list ---------------------- "; // use STL list iterators to print out the values stored in the container if possible (otherwise print out why it's not possible) cout << "---------------------- STL forward_list ---------------------- "; // use STL forward_list iterators to print out the values stored in the container if possible (otherwise print out why it's not possible) cout << "---------------------- STL deque ---------------------- "; // use STL deque iterators to print out the values stored in the container if possible (otherwise print out why it's not possible) cout << "---------------------- STL stack ---------------------- "; // use STL stack iterators to print out the values stored in the container if possible (otherwise print out why it's not possible) cout << "---------------------- STL queue ---------------------- "; // use STL queue iterators to print out the values stored in the container if possible (otherwise print out why it's not possible) cout << "---------------------- STL priority_queue ---------------------- "; // use STL priority_queue iterators to print out the values stored in the container if possible (otherwise print out why it's not possible) cout << " ---------------------- Determine the unique elements in the vector (using STL algorithms) and print them out ---------------------- "; // determine the unique elements in the vector (using STL algorithms) // Hint: You'll need to use a couple of different functions cout << "There are a total of " << << " unique integers: "; // print out the unique elements 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!