Listing 6 Pseudocode for a procedure to merge an arbitrary number of files

/* Program to merge an arbitrary number
 * sorted files */

open and read first line from each file
while (no file has been exhausted)
{
   determine which lines comes next
   print that line
   if (the corresponding file is now
      at end-of-file)
      delete it from the list of active files
   else
      get a fresh line from the file
}

/* End of File */