CS312 Lab 0:  Generic Linked List in C

 

Implement a generic doubly-linked or circularly-linked list. A generic linked list is a linked list that allows for arbitrary data types that are not homogenous. In C, this is accomplished with the use of the pointer void *.

Test your implementation by creating a linked list of mixed integers and doubles. The following types/declarations might help you start. They should go into your .h file.

#define INT 0
#define DOUBLE 1

typedef struct _number {
  int type;
  void *num;
  struct _number *prev;
  struct _number *next;
} Number;

typedef struct _integer {
  int data;
} Integer;

typedef struct _double {
  double data;
} Double;


Integer *make_int(int x);
Double *make_double(double x);
Number *make_number(int type, void *num);

Implement the functions and test by creating a list of 10 numbers (0-9), with the odd numbers being doubles and the even numbers being integers. Then go through the list and print them out.

To submit your lab, place all files into a single directory named LastnameFirstname. For example, my directory would be EatonEric. Then create a tar archive of that directory, such that the tar file expands to the directory (not a bunch of files). Copy that tar directory into ~eeaton/submit/cs312/lab0 on cs.brynmawr.edu to complete the submission.