Due: Monday, October 23 2017, 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.
  5. Improve your linked list and make it has no memory leak. You may need to have a new version of the generic linked list if your improvement introduces interface modification.


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.

    To check whether you've made your README file clear, you may ask yourself the following questions:

    • Does the README file identify the purpose and author of containing directory's contents?
    • Does the README file list every other file in the directory along with a short description of its purpose?
    • Does the README file use spacing and indentation to make its organization easily comprehended by the reader?
    • Does the README file include the compilation environment (i.e. the operating system it was developed on and the version of the compiler/interpreter that was used in development)?
    • Does the README file describe how to install (if necessary), compile (if necessary), and run the any programs in the directory?
    • Does the README file describe any command line arguments necessary for running programs in the directory?
    • Does the README file show the outputs of programs in the directory?
    • For the C assignments in CS333, the README serves as the write-up (for just the C-programming part). If your README is part of such a project, does it contain the information required by the tasks in the C-programming part of the project instructions? and only those?
    • If you have taken any coding extensions, does the README have a session for them?
  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.

© 2017 Ying Li. Page last modified: .