STARTING OUT WITH C++ MPL
STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 16, Problem 5PC

Rotate Left

The two sets of output below show the results of successive circular rotations of a vector. One set of data is for a vector of integers, and the second is for a vector of strings.

1 3 5 7

3 5 7 1

5 7 1 3

7 1 3 5

a b c d e

b c d e a

c d e a b

d e a b c

e a b c d

Write two template functions that can be used to rotate and output a vector of a generic type:

void rotateLeft(vector <T>& v)

void output(vector <T> v)

The first function performs a single circular left rotation on a vector, and the second prints out the vector passed to it as parameter. Write a suitable driver program that will allow you to test the two functions by generating output similar to the above. Verify that the program works with vectors whose element types are char, int, double, and string.

Blurred answer
Students have asked these similar questions
Write a function that adds the contents of two vectors using the following header: template<typename T>void addvector(vector<T> &v1, vector<T> &v2) Write a test program that reads in 6 int values in two vector, adds both and displays the result.
C++  Sort a vector Define a function named SortVector that takes a vector of integers as a parameter. Function SortVector() modifies the vector parameter by sorting the elements in descending order (highest to lowest). Then write a main program that reads a list of integers from input, stores the integers in a vector, calls SortVector(), and outputs the sorted vector. The first input integer indicates how many numbers are in the list. Ex: If the input is: 5 10 4 39 12 2 the output is: 39,12,10,4,2, For coding simplicity, follow every output value by a comma, including the last one. Your program must define and call the following function:void SortVector(vector<int>& myVec)     #include <iostream>#include <vector>using namespace std; /* Define your function here */ int main() {   /* Type your code here */    return 0;}   Enter program input - 5 10 4 39 12 2
You may insert an element into an arbitrary position inside a vector using an iterator. Write a function, insert(vector, value) which inserts value into its sorted position inside the vector. The function returns the vector after it is modified. #include <vector>using namespace std; vector<int>& insert(vector<int>& v, int value){ ................ return v; }

Chapter 16 Solutions

STARTING OUT WITH C++ MPL

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License