Due: Monday, October 24 2016, 11:59 pm

Prat I: Polymorphism in C

For this part, develop an example of polymorphism and demonstrate how C can implement polymorphic functions and types.


  1. Create a generic linked list class in C. First, create a LinkedList struct that has a head pointer and a Node struct that can hold an arbitrary pointer and a next pointer. You are free to use single- or doubly-linked lists. Then implement the following functions.

    • LinkedList *ll_create() creates a new LinkedList struct, initializes it, and returns it.
    • void ll_push(LinkedList *l, void *data) adds a node to the front of the list, storing the given data in the node.
    • void *ll_pop(Linked List *l) removes the node at the front of the list and returns the associated data.
    • void ll_append(LinkedList *l, void *data) adds a node to the end of the list, storing the given data in the node.
    • void *ll_remove(LinkedList *l, void *target, int (*compfunc)(void *, void *)) removes the first node in the list whose data matches target given the comparison function. The function returns the pointer to the data.
    • int ll_size(LinkedList *l) returns the size of the list.
    • void ll_clear(LinkedList *l, void (*freefunc)(void *)) removes all of the nodes from the list, freeing the associated data using the given function.
    • void ll_map(LinkedList *l, void (*mapfunc)(void *)) traverses the list and applies the given function to the data at each node.

    You can test your linked list function using this test function. Compile using:

    gcc -o clltest clltest.c yourLinkedList.c

    Extend the test function so it uses a linked list with a second data type.

Prat II: Polymorphism in Selected Languages

For this part, develop examples of polymorphism and demonstrate how the selected languages can implement polymorphic functions, classes ,and types.


  1. Implement a LinkedList class in your other two languages, making use of some form of polymorphism to implement the data structure. Create the same set of functions as above, but adapt the data types, as necessary. If you language enables templates, use them. Create a test function that demonstrates you can create linked lists to store two different types of data.

  2. Generate a wiki page that shows the examples in your languages. Explain how the language makes use of polymorphism. If your language has generics or templates, explain how it is implemented. These do not need to be long or detailed explanations, but should identify the benefits and drawbacks of the implementation method.


  1. A perfectly acceptable extension for any assignment is to do a third language.
  2. Implement more than one method of creating a generic implementation of a data structure in one of your languages. Explain how the methods differ and any benefits/drawbacks.
  3. Make a compilable and runnable haiku in the language that helps to demonstrate the concept of polymorphism. poly.py
  4. Implement the delete function for your linked list in C that can remove the node at any position in the list.


The submission of this project has three components:

  1. Codes: Your linked list implementation in C and the selected languages should be submitted to the fileserver. Please make the filename of your source codes meaningful.Note that the quality of your comments counts toward your grade.
  2. README: In this project, you need to submit a README file for your C codes and codes in the selected languages. The README file can be a .txt file. It should be well-organized in a way that readers can easily know the usage and the outputs of the source codes in C and the selected languages. In addition, the known bugs of your codes should also be indicated in the README file. Please also indicate the version of your C complier, your operationg system, and its version in the README file.
  3. Wiki write-up: The write-up of this project should have the following elements.
    • Title of the project and your name
    • The tutorials on polymorphism in the selected languages
    • Please include necessary code snapshots in your tutorials.

Please note that it is your responsibility to explicitly indicate the extensions you have taken. If you take the extension regarding linked list in C, please indicate explicitly in the codes and README file. If you take the extensions in selected languages, please indicate explicitly in your wiki write-up or source codes and README.

© 2016 Ying Li. Page last modified: .