153k views
3 votes
In order to detect repeated lines anywhere in the input, myuniq must keep track of all of the lines it has seen as it moves through the input. It will also need to count the frequency for each line. An array of structs to store this information seems like just the tool for the job, but we have a conundrum. How many entries do we need for this array

User HiddenUser
by
3.7k points

1 Answer

5 votes

Answer:

Step-by-step explanation:

The two solutions to this problem would be to either count the number of total lines in the input file and initialize the array with the exact number of lines, or use an ArrayList. The first solution would work since it would analyze the file first in order to make sure the array will fit every input line. The second solution will also work since ArrayLists are dynamic and do not have a fixed size. You can simply continue adding to the ArrayList and it will adjust its size accordingly.

User Tronbabylove
by
3.3k points