Generate all rotations of a given string | An efficient C ++ program to print all rotations of a string . ; Print all the rotated string . ; Concatenate str with itself ; Print all substrings of size n . Note that size of temp is 2 n ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printRotatedString ( char str [ ] ) { int n = strlen ( str ) ; char temp [ 2 * n + 1 ] ; strcpy ( temp , str ) ; strcat ( temp , str ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j != n ; j ++ ) printf ( " % c " , temp [ i + j ] ) ; printf ( " STRNEWLINE " ) ; } } int main ( ) { char str [ ] = " geeks " ; printRotatedString ( str ) ; return 0 ; }