How to sort the elements of vector


Discuss the below:

1. Create program definition with the following templates and methods:

// output miniVector v

template

void writeMiniVector(const miniVector& v);

// use insertion sort to place miniVector v in descending order

template

void sortMiniVector(miniVector& v);

Main Method

1. Declare: miniVector v;

2. Declare: randomNumber rnd;

3. call v.push_back(rnd.random(100)); to push 15 entries from 0-99 onto the vector

4. call writeMiniVector to output vector

5. call sortMiniVector to sort the vector

6. call writeMiniVector to output the sorted vector.

After you output the sorted vector:

Include: system("PAUSE"); after your output to pause the screen.

writeMiniVector Method (const miniVector& v)

1. Iterate through the vector v and output each element to the screen.

sortMiniVector Method (miniVector& v)

1. Sort the elements of vector v.

2. Since it is passed-by-reference, no return is necessary.

Example output of your program
Original: 59 18 60 91 49 47 83 93 55 52 15 36 83 56 91
Sorted: 93 91 91 83 83 60 59 56 55 52 49 47 36 18 15

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: How to sort the elements of vector
Reference No:- TGS01937064

Now Priced at $20 (50% Discount)

Recommended (92%)

Rated (4.4/5)