### Test Conditions

These questions must be completed under self-administered exam-like conditions.

You must time the test yourself and ensure you comply with the conditions below.

• You may complete this test in CSE labs or elsewhere using your own machine
• You may complete this test at any time before Friday 25 May 23:59:59
• The maximum time allowed for this test is 1 hour + 5 minutes reading time.
• You may first use 5 minutes to read the questions (no typing)
• You then must complete the test within 1 hour and submit your answers with give.
• You must complete the questions alone – you can not get help in any way from any person.
• You can not access your previous answers to lab or tut questions.
• You can not access web pages or use the internet in any way.
• You can not access books, notes or other written or online materials.
• You can not access your own files, programs, code …
• You can not access COMP1511 course materials except for language documentation linked below.

You may access this language documentation while attempting this test:

Any violation of the test conditions will results in a mark of zero for the entire weekly test component.

### Return How Many Even Numbers are in a Linked Lists

Download count_even_list.c, the starting code for this exercise or use this cp command:

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;
};

// 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

#### Testing

count_even_list.c also contains a main function which allows you to test your count_even function.This main function:

• converts the command-line arguments to a linked list
• assigns a pointer to the first node in the linked list to head
• prints the result.

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

#### Assumptions/Restrictions/Clarifications.

An even number is divisible by 2.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

#### Autotest Results

98% of 366 students who have autotested count_even_list.c so far, passed all autotest tests.

• 98% passed test 1
• 98% passed test 10
• 99% passed test 2
• 98% passed test 3
• 98% passed test 4
• 98% passed test 5
• 98% passed test 6
• 98% passed test 7
• 98% passed test 8
• 98% passed test 9

When you are finished working on this exercise you must submit your work by running give:

give cs1511 test11_count_even_list count_even_list.c

### Return How Many Numbers are Common to Two Linked Lists

Download list_intersection_size.c, the starting code for this exercise or use this cp command:

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;
};

// 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

#### Testing

list_intersection_size.c also contains a main function which allows you to test your intersection_size function.This main function:

• uses a command line argument of “-” ito separate the values for two linked lists.
• converts the command-line arguments before the “-” to a linked list
• assigns a pointer to the first node in the linked list to head1
• converts the command-line arguments after the “-” to a linked list
• assigns a pointer to the first node in the linked list to head2
• prints the result.

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

#### Assumptions/Restrictions/Clarifications.

intersection_size should return a single integer.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

#### Autotest Results

96% of 348 students who have autotested list_intersection_size.c so far, passed all autotest tests.

• 99% passed test 1
• 97% passed test 10
• 98% passed test 11
• 98% passed test 12
• 97% passed test 13
• 97% passed test 14
• 97% passed test 15
• 97% passed test 16
• 98% passed test 2
• 99% passed test 3
• 99% passed test 4
• 99% passed test 5
• 98% passed test 6
• 97% passed test 7
• 97% passed test 8
• 97% passed test 9

When you are finished working on this exercise you must submit your work by running give:

give cs1511 test11_list_intersection_size list_intersection_size.c

### Return Most Frequent Number in a Linked List

Download most_frequent_list.c, the starting code for this exercise or use this cp command:

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;
};

// 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 occuring 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.

#### Testing

most_frequent_list.c also contains a main function which allows you to test your most_frequent function.This main function:

• converts the command-line arguments to a linked list
• assigns a pointer to the first node in the linked list to head
• prints the result.

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

#### Assumptions/Restrictions/Clarifications.

most_frequent should return a single integer.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

#### Autotest Results

95% of 300 students who have autotested most_frequent_list.c so far, passed all autotest tests.

• 97% passed test 1
• 97% passed test 10
• 97% passed test 11
• 97% passed test 12
• 95% passed test 13
• 97% passed test 14
• 97% passed test 2
• 98% passed test 3
• 96% passed test 4
• 97% passed test 5
• 98% passed test 6
• 98% passed test 7
• 98% passed test 8
• 97% passed test 9

When you are finished working on this exercise you must submit your work by running give:

give cs1511 test11_most_frequent_list most_frequent_list.c

### Submission

When you are finished each exercise make sure you submit your work by running give.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

Help