CS312 Lab 0:  Generic Linked List in C

 

Implement a generic doubly-linked or circularly-linked list. A generic/polymorphic 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 *. In C++, you can implement a homogeous list of a parent class that has child classes with different configurations.

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.