...

/

Practice: Get Element at Position

Practice: Get Element at Position

Practice generic linked lists by writing functions operating on them.

Introduction

One of the challenging aspects of implementing a generic linked list is to write a proper allocGenericNode function, which works correctly regardless of the data type.

The other aspect is to figure out how to abstract the concrete handling of data types to keep the linked list functions generic. Our current approach is to pass function pointers as arguments to customize the code behavior for each data type.

After these things are in place, working with generic linked lists is similar to working with regularly linked lists. For this reason, we won’t insist on implementing many functions using generic linked lists, as it would be almost the same work as we did for regular lists.

However, to practice a bit, let’s try to write a function that returns the node’s value field at a given position, getElementAtPosition.

The getElementAtPosition function

This function will ...