/*The header file for the doubly linked lists library*/ typedef struct __dllist* dllist; struct __dllist { char * data; dllist next; dllist prev; }; /*Allocates a new node for the list*/ /* Purpose: Allocates a new node for the list. Preconditions: Memory available for allocation. Postconditions: Memory is allocated for a new list node. Problems: Unknown behavior when data is null Parameters: data - a pointer to a string, which will be copied into the data field of the new node. Produces: A pointer to the newly created node, or NULL if it could not be created. */ dllist newDLListNode(char* data); /*Inserts the new list after the existing one*/ /* Purpose: Inserts the new list after the existing one Preconditions: node is not null. Postconditions: new is joined onto the list. Problems: none. Parameters: node - the existing list. Should not be null. new - the list to insert into the existing one. Produces: Nothing. */ void insertAfter(dllist node, dllist new); /*Attaches the new list in front of the existing one*/ /*Attaches the new list in front of the existing one Purpose: Attaches the new list before of the existing one. Preconditions: node is not null Postconditions: The list new is inserted before node. Problems: None. Parameters: node - the existing list. new - the list to insert. Produces: Nothing. */ void insertBefore(dllist node, dllist new); /*removes the node from the list*/ /* Purpose: Frees up the memory needed by a list node. Preconditions: The node should be removed from any lists first. Postconditions: The memory it occupied is available for reallocation. Problems: None Parameters: node - dllist structure. Produces: Nothing */void delete(dllist node); /*Removes the node from the list, returns the pointer to the node that was removed (should be the same as the argument. Does not free up the memory of the node*/ /* Purpose: Removes the node from the list. Does not free up the memory. Preconditions: node is not null Postconditions: node is removed from the list but none of its information is changed. Problems: None. Parameters: node - the node to remove. Produces: The node that was passed to it. */ dllist takeOut(dllist node); /*Creates a new list from a file and returns the first element*/ /* Purpose: Creates a new list from a file. Preconditions: The file is already open with (at least) read permissions. The file has one list element on a line, blank lines are permissible. Postconditions: Each line of the file is its own element in a new list. Blank lines become empty elements. Problems: None. Parameters: f - the file to read from Produces: The first element of the list, with all the other elements attached. */ dllist readFromFile(FILE * f); /*Writes the list to a file*/ /* Purpose: Writes a list to a file. Preconditions: f is opened with at least write permissions. Postconditions: The list has been written to the file, with each element on its own line. Problems: None. Parameters: l - the list to write to file. May be null. f - the file to write to Produces: Nothing. */ void writeToFile(dllist l, FILE * f); /*Copies the list and quicksorts it. Returns the first element of the new list*/ /* Purpose: Uses a quicksort algorithm to sort the list. Preconditions: None. Postconditions: The original list is not changed. Problems: Does not bring about world peace. Parameters: l - the list to sort. May be null. Produces: a sorted copy of l */ dllist sort(dllist l); /*Returns the end of the list. The first node if lookforward is true, the last node otherwise*/ /* Purpose: Finds the end of the list. Preconditions: None. Postconditions: l is not changed. Problems: None. Parameters: l - the list to find the end of lookforward - if this is true (nonzero), then the beginning of the list is returned (l->prev->prev->...). Else the end of the list is returned (l->next->next->...) Produces: The end element of the list. */ dllist findEnd(dllist l, int lookforward); /*Returns the number of elements in the list*/ int countElements(dllist l); /* Purpose: Prints out all the elements of the list. Preconditions: None. Postconditions: Each element of l has been printed to stdout, one element on a line. When the printing is done, "Done printing" will be printed. Problems: None. Parameters: l - the list to print Produces: Nothing */ void printList(dllist l);