/* list.h is the header file for doubly linked list of strings. * It contains the delcaration of struct linkedlist, a pointer to it, * and delcarations of different functions provided by strList.c */ #include #include /* This #define seems unnecessary, it is defined because the authors find * it easier to type null than NULL and were half way through the coding * when they discovered they null is not defined by C. This is a remedy * definition. */ #define null NULL /* Max number of characters in a string. */ #define MAX 256 /* A pointer to struct lnode, defined in strList.c. */ typedef struct lnode* nodep; /* A wrapper struct for node. * Keeps track of the head, tail, and the current pointer of the list */ struct linkedlist{ nodep head; nodep tail; nodep current; }; typedef struct linkedlist* list; /* Functions. */ /* initialize(): Initialize a linked list. * Parameters : none * Return : a pointer to an empty doubly linked list. The first * and only node of the list is a dummy. */ list initialize(); /* reset(list ls) : sets the current of a given list to the node after dummy * Parameters : a pointer to the list. * Returns : none. */ void reset(list ls); /* isempty(list ls) : tests whether a given list is empty or not. * Parameters : a pointer to the list. * Returns : 0 if the list is not empty, 1 if empty. */ int isempty(list ls); /* advance(list ls) : moves the current node forward by one step. * Parameters : the pointer to the list. * Returns : 1 if adavnce succeeds, 0 if it fails. */ int advance(list ls); /* backoff(list ls) : moves the current node backward by one step. * Parameters : the pointer to the list. * Returns : 1 if backoff succeeds, 0 if it fails. */ int backoff(list ls); /* getcurrent(list ls) : returns the content of the current node. * Parameters : a pointer to the list. * Pre : the current cannot be the dummy node. * Returns : the content of the current node. */ char *getcurrent(list ls); /* addtoend(list ls, char *w) : add a node to the end of a given list. * Parameters : a pointer to the list, and * the string to be added. * Return : none */ void addtoend(list ls, char *w); /* insert(list ls, char *w) : Insert a node after the current node. * Parameters : a pointer to the list, the string to be added. * Return : none. * Post : The current node will be the new node. All other nodes remain in the original order. */ void insert(list ls, char *w); /* printcurrent(list ls): prints the content of the current node. * Parameters : the pointer to the list. * Returns : 1 if pritncurrent succeeds, 0 if it fails.. */ int printcurrent(list ls); /* listwrite(list ls, char* filename) : write the content of the list to * a designated file. * Parameters : a pointer to the list, * the name of a file * Return : 1 if listwrite succeeds, * 0 if it fails.. */ int listwrite(list ls, char *fileName); /* listprint(list ls) : prints out all the strings in the list in order. * Parameters : a pointer to the list. * Returns : none */ void listprint(list ls); /* listread(char *filename) : read a file into a list of strings * Parameters : the name of a file * Returns : pointer to the list. */ list listread(char *filename); /*The function concatenates sorted lists containing *elements less than the pivot, elements equals to the *pivot and elements greater than the pivot *Parameters:Three lists to be concatenated *PreConditions: All three lists are initialized *PostConditions:The concatenated list contains all the *elements in the three lists *Produces: A sorted list containing all the elements *of the concatenated lists */ list concatenate(list smaller, list eql, list greater); /*The function sorts a list using quicksort method *Parameters:The list to be sorted *PreConditions: The list is initialized *PostConditions:The sorted list has all the elements in the initial list *Produces: A sorted list */ list quicksort(list lst); /* deletecurrent(list ls) : deletes the current node of the list * Parmaeters : a pointer to the list. * Pre : the current node cannot be the head * Post : current points to the next node if current is * not the tail, otherwise current points to tail. * Returns : 1 if current is successfully deleted, else 0. */ int deletecurrent(list ls); /* find_nth_node(list ls, int n) : finds the nth node in a given list. * Parameters : the pointer to the list, a positive * integer indicating the position the node. * Returns : 1 if the node is found, 0 if not * Pre : n cannot exceed the length of the node * Post : current points to the nth node if found * : otherwise, current position is unknown. */ int find_nth_node(list ls, int n); /* delete_nth_node(list ls, int n) : deletes the nth node in ls. * Parameters : a pointer to the list, * Pre : n cannot exceed the length of the list. * Returns : 1 if node is successfully deleted, * 0 if the task fails. */ int delete_nth_node(list ls, int n); /* delete_elements(list ls, char[] str) : deletes all occurrences of the * string from the list * Parameters : a pointer to the list and a string * Returns : number of nodes deleted. */ int delete_elements(list ls, char *str); /* delete_element(list ls, char *str) : deletes the first occurence of str * Parameters : a pointer to the list and the * string to be deleted. * returns : 1 if the string is deleted,else 0. */ int delete_element(list ls, char str[]);