Question: Which is faster for a simple program, a vector or a list? Write two programs, vcount using a vector and lcount using a list. In

Which is faster for a simple program, a vector or a list?
Write two programs, vcount using a vector and lcount using a list.
In each program, generate a million random numbers between 0 and 9. Add them to the data structure. (see hint below on how to generate random numbers).
Then write a loop that goes from 0 to 9, uses the algorithm count, and prints how many 0's,1's, etc up through how many 9's occur in the data.
Find out how long each program takes to run by using the time program: time ./vcount and time ./lcount
Put the programs in your afs area.
Put a note on Moodle saying how long each took to run, and why you think one was faster than the other.
Hint: for random numbers, look at man srand Basically, you have to seed the random number generator once at the beginning. Typically that's done by saying
srand(time(0));
which will seed the random number generator with the current time. Then to generate a random number 0 through 9 use
rand()%10;

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 Programming Questions!