Results 1 to 6 of 6

Thread: Use of the rotate_copy() in CPP

  1. #1
    Join Date
    Jan 2010
    Posts
    29

    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.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    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 )
    ;

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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.

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    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

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    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;
      }
    }

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,491,542.63448 seconds with 15 queries