You must time the test yourself and ensure you comply with the conditions below.
cp -n /web/cs1511/18s1/activities/max_list/max_list.c .Note max_list.c uses the following familiar data type:
struct node { struct node *next; int data; };Your task is to add code to this function:
// return the maximum value in a linked list
int max_list(struct node *head) {
// PUT YOUR CODE HERE (change the next line!)
return 42;
}
max_list is given one argument, head, which is the pointer to the first node in a linked list.
Add code to max_list so that its returns the largest value in the linked list.
You can assume the list contains at least one element (is not empty).
For example if the linked list contains these 8 elements:
16, 7, 8, 12, 13, 19, 21, 12
max_list should return 21, because 21 is the largest value in the list
This main function:
Do not change this main function. If you want to change it, you have misread the question.
Your max_list function will be called directly in marking. The main function is only to let you test your max_list function
Here is how you use main function allows you to test max_list:
cp -n /web/cs1511/18s1/activities/max_list/max_list.c . dcc max_list.c -o max_list ./max_list 16 7 8 12 13 19 21 12 21 ./max_list 2 4 6 2 4 6 6 ./max_list 13 15 17 19 23 29 3 5 7 11 29 ./max_list 2 4 8 16 32 64 128 256 256 ./max_list 42 42
max_list can assume this list will contain at least one integer.
max_list should not change the linked list it is given. Your function should not change the next or data fields of list nodes.
max_list should not use arrays.
max_list should not call malloc.
max_list should not call scanf (or getchar or fgets).
You can assume the linked list only contains positive integers.
max_list should not print anything. It should not call printf.
Do not change the supplied main function. It will not be tested or marked.
When you think your program is working you can autotest
to run some simple automated tests:
1511 autotest max_list
give cs1511 test12_max_list max_list.c
cp -n /web/cs1511/18s1/activities/list_count_farnarkles/list_count_farnarkles.c .Note list_count_farnarkles.c uses the following familiar data type:
struct node { struct node *next; int data; };Your task is to add code to this function:
// Return the number of farnarkles in the two lists, i.e. the number of
// values which occur at the same position in both linked lists.
int count_farnarkles(struct node *head1, struct node *head2) {
// PUT YOUR CODE HERE (change the next line!)
return 42;
}
count_farnarkles is given two arguments, head1 and head2, which are pointers to the first node of linked lists.
Add code to count_farnarkles so that returns a count of how many places the two lists have the same value in the same position.
Note in week 5, you wrote an equivalent function for 2 arrays of fixed equal length. In this case, the lists may be any length and the two lengths may be unequal.
For example, if the two lists contain these values:
1, 4, 1, 5, 9, 2, 1, 8 1, 1, 8, 2, 9, 5
count_farnarkles should return 2 because both lists have the same value (1) at position 0 and the same value (9) at position 4.
This main function:
Do not change this main function. If you want to change it, you have misread the question.
Your count_farnarkles function will be called directly in marking. The main function is only to let you test your count_farnarkles function
Here is how the main function allows you to test count_farnarkles:
cp -n /web/cs1511/18s1/activities/list_count_farnarkles/list_count_farnarkles.c . dcc list_count_farnarkles.c -o list_count_farnarkles ./list_count_farnarkles 3 1 4 - 2 7 1 8 3 0 ./list_count_farnarkles 1 2 3 4 - 2 1 3 8 1 ./list_count_farnarkles 5 5 6 5 - 6 5 5 5 2 ./list_count_farnarkles 3 5 7 - 3 5 19 7 23 29 2 ./list_count_farnarkles 1 2 3 4 5 6 - 3 2 1 1 ./list_count_farnarkles - 1 2 3 4 0 ./list_count_farnarkles 4 3 2 1 - 0 ./list_count_farnarkles - 0
The linked list may be unequal length.
The linked lists may be any length.
Either or both linked lists may be empty (contain no elements).
count_farnarkles should not change the linked lists it is given. Your function should not change the next or data fields of list nodes.
count_farnarkles should not use arrays.
count_farnarkles should not call malloc.
count_farnarkles should not call scanf (or getchar or fgets).
count_farnarkles should not print anything. It should not call printf.
Do not change the supplied main function. It will not be tested or marked.
When you think your program is working you can autotest
to run some simple automated tests:
1511 autotest list_count_farnarkles
give cs1511 test12_list_count_farnarkles list_count_farnarkles.c
cp -n /web/cs1511/18s1/activities/list_delete_repeated/list_delete_repeated.c .Note list_delete_repeated.c uses the following familiar data type:
struct node { struct node *next; int data; };Your task is to add code to this function:
struct node *delete_repeated(struct node *head) {
// PUT YOUR CODE HERE (change the next line!)
return NULL;
}
delete_repeated is given one argument, head, a pointer to the first node in a linked list.
Add code to delete_repeated so that it deletes any consecutive repeated values from the linked list.
If there are no consecutive repeated values, the list should not be changed.
delete_repeated should return a pointer to the new list.
delete_repeated should call free to free the memory of the node it deletes.
For example if the linked list contains these 9 elements:
16, 16, 7, 8, 12, 19, 19, 19, 7
delete_repeated should return a pointer to a list with 6 elements:
16, 7, 8, 12, 19, 7
This main function:
Do not change this main function. If you want to change it, you have misread the question.
Your delete_repeated function will be called directly in marking. The main function is only to let you test your delete_repeated function
cp -n /web/cs1511/18s1/activities/list_delete_repeated/list_delete_repeated.c . dcc list_delete_repeated.c -o list_delete_repeated ./list_delete_repeated 16 16 7 8 12 19 19 19 7 [16, 7, 8, 12, 19, 7] ./list_delete_repeated 42 42 42 42 42 42 42 [42] ./list_delete_repeated 42 42 42 77 42 42 42 42 [42, 77, 42] ./list_delete_repeated 1 0 1 0 1 0 1 0 1 [1, 0, 1, 0, 1, 0, 1, 0, 1] ./list_delete_repeated 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 [1, 2, 3, 4, 5] ./list_delete_repeated []
Similarly if there are n repeated values delete_repeated may delete any n - 1 of the list nodes.
delete_repeated should call free to free the memory for the node it deletes
delete_repeated should not change the data fields of list nodes.
delete_repeated should not use arrays.
delete_repeated should not call malloc.
delete_repeated should not call scanf (or getchar or fgets).
delete_repeated should not print anything. It should not call printf.
Do not change the supplied main function. It will not be tested or marked.
When you think your program is working you can autotest
to run some simple automated tests:
1511 autotest list_delete_repeated
give cs1511 test12_list_delete_repeated list_delete_repeated.c
You can run give multiple times. Only your last submission will be marked.
Don't submit any exercises you haven't attempted.
If you are working at home, you may find it more convenient to upload your work via give's web interface.
Remember you have until Saturday 2 June 23:59:59 to complete this test.
Automarking will be run several days after the submission deadline for the test. When complete you can view automarking here and you can view the the resulting mark via give's web interface