Wednesday, May 11, 2022

Write a program in C++ using class to print all the rotating strings of a given string. For example, if I/P String = "CLASS" the O/P should be CLASS, LASSC, ASSCL, SSCLA, SCLAS

 #include <iostream>

using namespace std;
#include <string.h>
#include <algorithm>
/*CLASS,LASSC,ASSCL,SSCLA,SCLAS*/
int main()
{
    string s;
    s = "CLASS";
    int n = s.size();
    for (int i = 0; i < n ; i++)
    {
        cout<<s<<endl;
        rotate(s.begin(), s.begin() + 1, s.end());//(starting , index to rotate,till which index to rotate)
    }

    return 0;
}
template <class ForwardIterator>
  void rotate (ForwardIterator first, ForwardIterator middle,
               ForwardIterator last)
{
  ForwardIterator next = middle;
  while (first!=next)
  {
    swap (*first++,*next++);
    if (next==last) next=middle;
    else if (first==middle) middle=next;
  }
}*/

No comments:

Software scope

 In software engineering, the software scope refers to the boundaries and limitations of a software project. It defines what the software wi...

Popular Posts