The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 56 Weeks Ago, 4 Days Ago |
| Questions Answered: | 7570 |
| Tutorials Posted: | 7352 |
BS,MBA, PHD
Adelphi University/Devry
Apr-2000 - Mar-2005
HOD ,Professor
Adelphi University
Sep-2007 - Apr-2017
Write a program that reads two input files whose lines are ordered by a key data field. Your program should merge these two files, writing an output file that contains all lines from both files ordered by the same key field. As an example, if two input files contain student names and grades for a particular class ordered by name, merge the information as shown below

You must read one line of a file at a time and either write it or the last line read from the other data file to the output file. A common merge algorithm is the following:
Read a line from each data file
While the end of both files has not been reached
If the line from file 1 is smaller than the line from file 2
Write the line from file 1 to the output file and read a new
line from file 1
Else
Write the line from file 2 to the output file and read a new line from file 2.
Write the remaining lines (if any) from file 1 to the output file.
Write the remaining lines (if any) from file 2 to the output file.
Ple-----------ase----------- fi-----------nd -----------the----------- co-----------de -----------bel-----------ow.----------- Co-----------de -----------is -----------com-----------men-----------ted----------- so----------- th-----------at -----------it -----------is -----------eas-----------y t-----------o u-----------nde-----------rst-----------and-----------. A-----------lso-----------, f-----------ind----------- at-----------tac-----------hed----------- fi-----------les----------- us-----------ed -----------in -----------tes-----------t r-----------un -----------of -----------pro-----------gra-----------m: -----------fil-----------e1.-----------txt-----------, f-----------ile-----------2.t-----------xt