Use of the rotate_copy() in CPP
Hello, I am the student of the Computer Science. I had also learned the C++ programming language in the BSC. I could also have the knowledge about the functions that could be in-built into the C++ programming language libraries. I could must have to submit the note on the rotate_copy() function. So, I would like to know the information about the rotate_copy() function of the C++ language. I want to know how can I Use the rotate_copy() function in C++ programming language. Thus, Anyone could have the knowledge of the rotate_copy() function of the C++ programming language.
Re: Use of the rotate_copy() in CPP
Hi, The rotate_copy() function can be used in the C++ language to copy the the given specified range that can be rotated. The rotate_copy() function can be the member of the <algorithm> header files. The following can be the syntax of the rotate_copy() function in the C++ language :
Code:
template <class FrwrdItrtr, class OtptItrtr>
OtptItrtr rotate_copy ( FrwrdItrtr fst, FrwrdItrtr mdl,
FrwrdItrtr lst, OtptItrtr rslt )
;
Re: Use of the rotate_copy() in CPP
Hello, According to me the rotate_copy() function can be used in the C++ language to rotate the elements that can be available in the given specified range. The behavior of the rotate_copy() function template can be similar to the following as :
Code:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int myints[] = {10,20,30,40,50,60,70};
vector<int> mvctr;
vector<int>::iterator it;
mvctr.resize(7);
rotate_copy(myints,myints+3,myints+7,mvctr.begin());
cout << "mvctr contains:";
return 0;
}
Output:
Code:
mvctr contains: 40 50 60 70 10 20 30
Re: Use of the rotate_copy() in CPP
The rotate_copy() function algorithm of the C++ language can moves an elements in the given specified range [strt,nd) such that the middle an element can now where start used to be, (midl+1) can now at the (strt+1) etc. The rotate_copy() function can runs in the linear time. I hope this information about the rotate_copy() function can be enough for you to know about the rotate_copy() function of the C++ language.
Re: Use of the rotate_copy() in CPP
There can be one more example code that can demonstrates you about the rotate_copy() function of the C++ language :
Code:
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main()
{
string t("Software Engineering ");
vector<char> vctr(t.begin(), t.end());
rotate_copy(vctr.begin(), vctr.begin() + 9,vctr.end());
for(int j=0; j<vctr.size(); j++)
{
cout << vctr[j] ;
}
return 0;
}
The output of the above code :
Code:
Engineering Software
Re: Use of the rotate_copy() in CPP
Hello, According to me the rotate_copy() function can be used in the C++ language to rotate_copy the elements that can be available in the given specified range. The behavior of the rotate_copy() function template can be similar to the following as :
Code:
template <class FrwrdItrtr>
void rotate_copy ( FrwrdItrtr fst, FrwrdItrtr mdl,
FrwrdItrtr lst )
{
FrwrdItrtr nxt = mdl;
while (fst!=nxt)
{
swap (*fst++,*nxt++);
if (nxt==lst) nxt=mdl;
else if (fst == mdl) mdl=nxt;
}
}