Recovering Lines from split
Once split array is filled, we can recover the word boundaries for each line. The following code recovers the lines of text in our final solution. In the code, lineEnd
is a list
that stores the index of the last word in each line. Its computation is also shown in the last figure.
Once the line endings are determined, we can justify text by inserting the right amount of spaces between words, which is easy to do.
xxxxxxxxxx
11
Routine: getLines
Input: splitArray
Output: lineEnd list
​
1. int current = 0;
2. do
a. lineEnd.add(split[current])
b. current = split[current]
c. current = current+1
while(current < split.length )
3. return lineEnd
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment