1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aliina [53]
3 years ago
8

Write a program that creates a list (STL list) of 100 random int values. Use the iterators to display all the values of the list

in order and in reverse order. Use the sort function to sort the list of values and output the list. g
Computers and Technology
1 answer:
sertanlavr [38]3 years ago
4 0

Answer:

The program is as follows:

#include <bits/stdc++.h>

#include <iostream>

using namespace std;

int main(){

  list <int> myList;

  for(int i=0;i<100;i++){  

      myList.push_back(rand()%100);       }

   list <int> :: iterator it;

   cout<<"Forward: ";

   for(it = myList.begin(); it != myList.end(); ++it){

       cout <<*it<<" ";    }

   

   cout<<"\nReversed: ";

   std::copy(myList.rbegin(),myList.rend(),std::ostream_iterator<int>(std::cout, " "));

        myList.sort();  

   cout<<"\nSorted: ";

   for(it = myList.begin(); it != myList.end(); ++it){

       cout <<*it<<" ";    }

   return 0;

}

Explanation:

This declares the list

  list <int> myList;

The following iteration generates 100 random integers into the list

<em>   for(int i=0;i<100;i++){  </em>

<em>       myList.push_back(rand()%100);       } </em>

This initializes an iterator

   list <int> :: iterator it;

This prints the header "Forward"

   cout<<"Forward: ";

This iterates through the list and prints it in order

<em>    for(it = myList.begin(); it != myList.end(); ++it){ </em>

<em>        cout <<*it<<" ";    } </em>

    This prints the header "Reversed"

   cout<<"\nReversed: ";

This uses ostream_iterator to print the reversed list

   std::copy(myList.rbegin(),myList.rend(),std::ostream_iterator<int>(std::cout, " "));

This sorts the list in ascending order

        myList.sort();

This prints the header "Reversed"  

   cout<<"\nSorted: ";

This iterates through the sorted list and prints it in order

   for(it = myList.begin(); it != myList.end(); ++it){

       cout <<*it<<" ";    }

You might be interested in
Imagine that you need to prepare for three end-of-term tests. What steps will you take to make sure your study time is well spen
ziro4ka [17]

Answer:

I will also choose a good study area and copy them and paste it

4 0
2 years ago
Which one of the secondary storage types below would be best if you wanted to edit files and re-save them to secondary storage?
jenyasd209 [6]
USB drive
the cloud
google docs
google drive
7 0
3 years ago
How can you best explain server side caching with web pages​
maksim [4K]

Answer:

Server side web caching typically involves utilizing a web proxy which retains web responses from the web servers it sits in front of, effectively reducing their load and latency.

Explanation:

4 0
3 years ago
How do i get my laptop to connect to wifi?​
Rina8888 [55]

Answer:

open your laptop go to the wifi or service icon. Look for your wifi and put in the password

4 0
3 years ago
Read 2 more answers
From the Table Style Options area of the Design tab, you select Banded Columns. What will happen to your table?
lubasha [3.4K]
I think it would be A. Every other column will have a border added to it.
4 0
3 years ago
Read 2 more answers
Other questions:
  • Suppose you have two arrays of ints, arr1 and arr2, each containing ints that are sorted in ascending order. Write a static meth
    7·1 answer
  • Computer a has an overall cpi of 1.3 and can be run at a clock rate of 600mhz. computer b has a cpi of 2.5 and can be run at a c
    11·1 answer
  • Array is special variable that can handle more than one value.
    6·1 answer
  • How are additional slides added to presentations? select all that apply
    10·1 answer
  • Having one password for all accounts is an easy way to remember passwords, but it will expose you to what risk?
    15·1 answer
  • What are three metrics used to define consistent network application availability?
    5·1 answer
  • Every modern nation has a Central Bank. Which of the following is the Central Bank for these United States?
    14·2 answers
  • Advantages of desktop publishing over traditional methods include       
    11·1 answer
  • Which of the following is the fastest computer processing speed?
    10·1 answer
  • What is containment and why is it part of the planning process
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!