0% found this document useful (0 votes)
30 views2 pages

Department of Computer Science CSI311 File Systems and Data Management 2012/2013 Lab 1 - Merging Sequential Files

This document provides an introduction and algorithm for merging two sequentially ordered files into a single file ordered on their common key field. The introduction gives an example of merging two employee files ordered by employee ID. The algorithm reads one record from each file, writes the record with the smaller key to the output file, then replaces it in the input file, repeating until a terminator key is reached. Exercises are given to implement the merger as a program using text and binary file formats.

Uploaded by

T'aich Makgetho
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Department of Computer Science CSI311 File Systems and Data Management 2012/2013 Lab 1 - Merging Sequential Files

This document provides an introduction and algorithm for merging two sequentially ordered files into a single file ordered on their common key field. The introduction gives an example of merging two employee files ordered by employee ID. The algorithm reads one record from each file, writes the record with the smaller key to the output file, then replaces it in the input file, repeating until a terminator key is reached. Exercises are given to implement the merger as a program using text and binary file formats.

Uploaded by

T'aich Makgetho
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Department of Computer Science CSI311 File Systems and Data Management 2012/2013 Lab 1 Merging Sequential Files

Introduction Two sequential files, having the same component type and sequenced on the same key field, can be combined to produce a single file sequenced on the common key. For example, a file containing the following fictitious employee information: 10001 Mercy Baitseng 10002 Kedirileng Metshameko 10103 Kenny Smart 10120 Bontle Muzila And another file containing the following information 10011 John Hamilton 10053 Mogorosi Modise 10055 Gaone Mabase 10133 David Calvin Both sequenced on Employee ID, when merged, will produce the following: 10001 Mercy Baitseng 10002 Kedirileng Metshameko 10011 John Hamilton 10053 Mogorosi Modise 10055 Gaone Mabase 10120 Bontle Muzila 10133 David Calvin

Page 1/2

An algorithm for accomplishing this could be written as (assuming both files are ordered): 1. Read one record from each input file 2. Move the input record with the smaller key to the output record, and replace the input record. 3. WHILE output record key <> Terminator DO BEGIN 3.1 Write output record to output file 3.2 Move the input record with smaller key to the output record, and replace the input record END Reading records from a specified file requires one to keep checking for the end of file. At the end of the file the procedure should set the record read to Terminator whose value should be greater than the largest record to be processed.

Exercises: 1. Create the two files given as text files and write the merger program in C++ or Java 2. Write the necessary programs to read and store the two input text files as binary files, and modify your merger program to merge them into a third file.

Page 2/2

You might also like