A crude text formatter.

[ C code | Pascal code ]

Last updated 19 August 1996. A few minor bugs in the C and Pascal code have been fixed. If your compiler accepted the previous versions, then you probably do not need to worry about the differences. If your compiler did not accept the previous versions, then you probably have already found and fixed these bugs yourself.

A small file of test data is available.


When written in C, the text formatter consists of 3 or 5 files. You job is to replace the first of these files with an optimal and efficient implementation of ChooseLineBreaks. You should be able to leave the other files unchanged.

  1. Either linebreaks2.c (the greedy algorithm) or linebreaks3.c (an optimal but inefficient algorithm) or your own optimal and efficient algorithm.
  2. linebreaks.h
  3. lists.h (not required by the greedy algorithm)
  4. lists.c (not required by the greedy algorithm)
  5. main.c


Two versions of the Pascal code are available:

  1. A greedy algorithm
  2. An optimal but inefficient algorithm