CS2
Recursion
12
Anagram
nHere’s the second sample recursive method for nonnumerical application. The routine lists all anagrams of a given word.
Word
C A T
C T A
A T C
A C T
T C A
T A C
Anagrams
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;
      }
   }
}