You must time the test yourself and ensure you comply with the conditions below.
cp -n /web/cs1511/18s1/activities/count_even_list/count_even_list.c .Note count_even_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 number of even values in a linked list
int count_even(struct node *head) {
// PUT YOUR CODE HERE (change the next line!)
return 42;
}
count_even is given one argument, head, which is the pointer to the first node in a linked list.
Add code to count_even so that its returns the number of even values in the linked list.
For example if the linked list contains these 8 elements:
16, 7, 8, 12, 13, 19, 21, 12
count_even should return 4, because these 4 elements are even:
16, 8, 12, 12
This main function:
Do not change this main function. If you want to change it, you have misread the question.
Your count_even function will be called directly in marking. The main function is only to let you test your count_even function
Here is how you use main function allows you to test count_even:
cp -n /web/cs1511/18s1/activities/count_even_list/count_even_list.c . dcc count_even_list.c -o count_even_list ./count_even_list 16 7 8 12 13 19 21 12 4 ./count_even_list 2 4 6 2 4 6 6 ./count_even_list 3 5 7 11 13 15 17 19 23 29 0 ./count_even_list 2 4 8 16 32 64 128 256 8 ./count_even_list 0
count_even should return a single integer.
count_even should not change the linked list it is given. Your function should not change the next or data fields of list nodes.
count_even should not use arrays.
count_even should not call malloc.
count_even should not call scanf (or getchar or fgets).
You can assume the linked list only contains positive integers.
count_even 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 count_even_list
give cs1511 test11_count_even_list count_even_list.c
cp -n /web/cs1511/18s1/activities/list_intersection_size/list_intersection_size.c .Note list_intersection_size.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 values which occur in both linked lists
// no value is repeated in either list
int intersection_size(struct node *head1, struct node *head2) {
// PUT YOUR CODE HERE (change the next line!)
return 42;
}
intersection_size is given two arguments, head1 and head2, which are pointers to the first node of linked lists.
Add code to intersection_size so that its returns the number of values that occur in both linked list.
Assume no value occurs more than once in either linked list.
For example, if the two lists contain these values:
3, 1, 4 2, 7, 1, 8, 3
intersection_size should return 2, because these 2 elements occur in both lists:
1, 3
This main function:
Do not change this main function. If you want to change it, you have misread the question.
Your intersection_size function will be called directly in marking. The main function is only to let you test your intersection_size function
Here is how the main function allows you to test intersection_size:
cp -n /web/cs1511/18s1/activities/list_intersection_size/list_intersection_size.c . dcc list_intersection_size.c -o list_intersection_size ./list_intersection_size 3 1 4 - 2 7 1 8 3 2 ./list_intersection_size 16 7 8 12 - 13 19 21 12 1 ./list_intersection_size 2 4 6 - 2 4 6 3 ./list_intersection_size 3 5 7 11 13 - 15 17 19 23 29 0 ./list_intersection_size 1 2 3 4 - 3 2 1 3 ./list_intersection_size - 1 2 3 4 0 ./list_intersection_size 4 3 2 1 - 0 ./list_intersection_size - 0
No value will occur more than once in either linked list.
intersection_size should not change the linked lists it is given. Your function should not change the next or data fields of list nodes.
intersection_size should not use arrays.
intersection_size should not call malloc.
intersection_size should not call scanf (or getchar or fgets).
intersection_size 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_intersection_size
give cs1511 test11_list_intersection_size list_intersection_size.c
cp -n /web/cs1511/18s1/activities/most_frequent_list/most_frequent_list.c .Note most_frequent_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 value which occurs most frequently in a linked list
// if several values are equally most frequent
// the value that occurs earliest in the list is returned
int most_frequent(struct node *head) {
// PUT YOUR CODE HERE (change the next line!)
return 42;
}
most_frequent is given one argument, head, which is the pointer to the first node in a linked list.
Add code to most_frequent so that its returns the most frequently occurring value in the linked list.
For example if the linked list contains these 8 elements:
655 10 204 8192 76 38 204 43912 204
most_frequent should return 204, because it is the most frequently occurring integer -- it appears 3 times.
For example if the linked list contains these 8 elements:
7 8 12 3 12 3 8
most_frequent should return 8.
There is a tie for most frequently occurring integer - 3, 8 and 12 all occur twice.
8 occurred first in the list so it should be returned.
You are not permitted to use arrays or malloc in your function.
This main function:
Do not change this main function. If you want to change it, you have misread the question.
Your most_frequent function will be called directly in marking. The main function is only to let you test your most_frequent function
Here is how you the main function allows you to test most_frequent:
cp -n /web/cs1511/18s1/activities/most_frequent_list/most_frequent_list.c . dcc most_frequent_list.c -o most_frequent_list ./most_frequent_list 655 10 204 8192 76 38 204 43912 204 204 ./most_frequent_list 5 4 6 5 4 6 5 ./most_frequent_list 3 5 7 11 13 15 3 17 19 23 29 13 3 3
most_frequent should not change the linked list it is given. Your function should not change the next or data fields of list nodes.
most_frequent should not use arrays.
most_frequent should not call malloc.
most_frequent should not call scanf (or getchar or fgets).
You can assume the linked list contains at least one integer.
most_frequent 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 most_frequent_list
give cs1511 test11_most_frequent_list most_frequent_list.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 Friday 25 May 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