Practice Linked List Questions

Linked List Warm-up Exam Questions: List Sum

Linked List Practice Exam Questions

The three lab activities for this week are intended as practice linked list exam questions.

You should make sure you are able to complete them on your own (although it’s fine to work on them with your lab partner) – if you’re able to complete these questions, you should be able to get 100% in the exam.

List Find Largest

This is an exercise in the Week 13 lab – go to the lab page for more details.

int listFindLargest (List l);

List Delete Largest

This is an exercise in the Week 13 lab – go to the lab page for more details.

int listDeleteLargest (List l);

List Delete Contains

This is an exercise in the Week 13 lab – go to the lab page for more details.

int listDeleteContains (List l);

Previous Lab Exercises

Other lab exercises from previous weeks that are about the level of a linked list exam question include:

Lab List Count Favourite

Lab List Get Middle

Lab List Insert Nth

Lab List Delete Nth

Lab List Is Ordered

Additional Practice Exam Questions

Other non-lab exercises for additional practice:

Are Lists Identical?

Returns TRUE if the lists are identical (in value), and FALSE otherwise.

For example, if the two lists were:

1 -> 2 -> 3 -> 4 -> 5 -> X
1 -> 2 -> 3 -> 4 -> 5 -> X

Your function should return TRUE, because the lists have the same values in each position.

As another example, if the two lists were:

1 -> 2 -> 3 -> 4 -> 5 -> X
1 -> 2 -> 3 -> 4 -> X

Your function should return FALSE, because the two lists are not the same – they are different lengths, and so cannot be identical.

As another example, if the two lists were:

1 -> 2 -> 3 -> 4 -> 5 -> X
5 -> 4 -> 3 -> 2 -> 1 -> X

Your function should return FALSE, because the two lists are not the same – they have different values.

The function must have this prototype: int listsIdentical(List first, List second);

Delete Odd

Deletes all of the odd elements in a list, i.e.

2 -> 3 -> 4 -> 5 -> 6 -> X

would become

2 -> 4 -> 6 -> X

The function must have this prototype: int listDeleteOdd(List list);

List Concatenate

Join two lists together:

Move all the elements from the second list to the end of the first list (in order). This leaves the second list empty, and all the elements are now in the first list.

For example, if the two lists were:

[ first] -> 1 -> 2 -> 3 -> 4 -> 5 -> X
[second] -> 1 -> 2 -> 3 -> X

Your function should change the lists, so that they look like this:

[ first] -> 1 -> 2 -> 3 -> 4 -> 5 -> 1 -> 2 -> 3 -> X
[second] -> X

As another example, if the two lists were:

[ first] -> 1 -> 2 -> 3 -> 4 -> 5 -> X
[second] -> 10 -> 20 -> 30 -> X

Your function should change the lists, so that they look like this:

[ first] -> 1 -> 2 -> 3 -> 4 -> 5 -> 10 -> 20 -> 30 -> X
[second] -> X

As another example, if the two lists were:

[ first] -> X
[second] -> 10 -> 20 -> 30 -> X

Your function should change the lists, so that they look like this:

[ first] -> 10 -> 20 -> 30 -> X
[second] -> X

The function must have this prototype:

void listConcatenate (List to, List from);

List Ordered Delete

Remove any “unordered” elments (i.e. leave the list in non-decreasing order)

For example:

1 -> 4 -> 2 -> 3 -> 6 -> 6 -> 10 -> 4 -> X

would become

1-> 4 -> 6 -> 6 -> 10 -> X

The function must have this prototype:

void orderedDelete (List l);

Linked List Warm-up Exam Questions

List Sum

This is an exercise in the Week 13 lab – go to the lab page for more details.

int listDeleteContains (List l);

Previous Lab Exercises

Other lab exercises from previous weeks that are good warm-up activities include:

Lab List Length

Lab List Print

Lab List Get Nth

Lab List Contains

Lab List Insert Head

Lab List Insert Tail

Lab List Delete Head

Lab List Delete Tail