Given an input file that contains a number of lists specified as the first number in the file and wherein each list will consist of a number of elements in the list, and a list of integers, or a list of strings, in any order, create a singly linked list of the numbers or in a separate list, the strings and so on for however many lists there are in the input file. Then once the lists are completely linked, total the numbers in the mode described below. Likewise, concatenate the strings as described below. These tasks should be accomplished using pointer manipulations only, that is arrays are not allowed. Also, make sure to demonstrate good memory management techniques.
1 Objectives
1.1 Inputs
There are two basic inputs, the input file name, passed via the command line, and the input file data defined below.
1.1.1 Command Line arguments
The input file name will be input as follows:
- pointerFun filename.ext
- In the event that the input file is not available or there is an error finding the file, an appropriate error message shall be displayed. Use the example below for guidance.
- pointerFun ERROR: File bogusFilename not found.
1.1.2 Input File fields
The first line of the file will have a single positive integer k, representing the number of lists in the file. Each list will follow. The first line of each list will have an integer number that represents the number of elements to be read and added to the linked list created for this list of inputs. The linked list should preserve the order in which the elements are read in.
Please note that it is incumbent upon the program to determine if the list contains strings or integers. The input file will contain the appropriate number of elements corresponding to the number of elements specified for the test case.
HINT: If the list is a list of strings, it would be highly advantageous to create a linked list structure that contained a pointer to the malloced string buffer. A list of integers could contain a linked list structure that contains integer data.
The input file, shown below, will NOT include comments. The comments and line spacing shown below are for clarification.
2 //Number of test cases
4 //The count of numbers in the list
6 //First number in the list
- //Second number in the list
- //Third number in the list
- //Fourth number in the list
4 //The count of strings in the list
blue //The first string in the list
dog //The second string in the list
red //The third string in the list
cat //The fourth string in the list
The actual files data would be as shown below:
2
4
6
4
5
6 4 blue dog red cat
2 Process
The program can assume that once a list of integers or strings has begun, the rest of the list will be of the appropriate type. That is a list of integers will always contain integers thru the end of the list. This will also be true for strings.
Also note that the program will have to walk the singly linked list to get every other element, then walk the list again to get the elements that were not totaled or concatenated in the first pass.
In the event the list contains strings make sure to create an output buffer that will be large enough for every string and the terminating NULL.
3 Outputs
The output of the program will be for however many lists were read in and the corresponding data for each list.
For the data shown above the outputs are shown below.
The total of the odd numbered numbers 6, 5 is 11
The total of the even numbered numbers 4, 6 is 10
The concatenation of (blue, red) is blue red The concatenation of (dog, cat) is dog cat
Reviews
There are no reviews yet.