1 Overview

This project entails you implementing a generic doubly-linked list ADT dllist in C with a header node as pictured below.

Figure: see image.

Here is file dllist.h:

#include < stdbool.h >
#ifndef DLLIST_H
#define DLLIST_H
typedef struct header *dllist;
dllist createList(void);
// returns a newly created empty list; must be called before
// using list routines

void destroyList(dllist dl);
// deallocates entire list (the nodes; does not free data); operation undefined if list
// hasn’t been created with createList; does nothing if dl==NULL. List is undefined
// after operation.

void clearList(dllist dl);
// deallocates list items (nodes only, not data) (if applicable) and sets list to empty,
// does nothing if dl==NULL

void *getItem(dllist,int);
// returns item at location if it exists, otherwise
// returns NULL

int addItem(dllist,void *item);
// adds item to end of list; item should be created at
// runtime with malloc (in order for it to be free’ed later).
// Returns index of new item or -1 if add was unsuccesful

int insertItem(dllist l,int i,void * item);
// inserts item into list at position i; item should be created
// at runtime with malloc (in order for it to be free’ed later).
// Returns index of new item or -1 if unsuccessful; operation is
// successful when 0 <= i <= listSize(l) (0 is the first item in
// the list)

bool removeItem(dllist,int i);
// removes node from list at position i and deallocates it (does not free the data),
// returns true if operation successful, false otherwise

bool setItem(dllist,int loc,void *);
// replaces (overwrites) item in list at position loc, returns
// true if operation is succesful, false otherwise

int listSize(dllist);
// returns current number of items in list

bool listEmpty(dllist);
// returns true if list is empty, false otherwise

#endif

You may not modify this file. You have may define your two node structures (i.e. your header and list nodes) in any way that you choose as long as you implement a header node structure pointing to both the head and tail of a doubly-linked list. Your data should be of type void * to allow data of any type to be stored in the list. Note that all memory management of the data is left to the user of the module - your code should not free up any actual data stored in your container.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.