CS2
Recursion
13
Anagram Solution: Rotate and Recurse
nThe basic idea is to recurse on a sub-word after every rotation. Here’s how:
C
A
T
Recursion
A
T
C
T
C
A
Recursion
Recursion
Rotate Left
Rotate Left
C A T
C T A
A T C
A C T
T C A
T A C
In pseudocode the above method is expressed as follows:

public void directoryListing( File dir )
{
   //assumption: dir represents a directory
   fileList = an array of names of files and
         subdirectories in the directory dir;

   for (each element in fileList) {
     if (an element is a file) {
       output the element’s filename;  //end case: it’s                            //a file.
     }
     else { //recursive case: it’s a directory
       call directoryListing with element as an argument;
      }
   }
}