/* * This module is for storing strings in a doubly-linked list * The strings can be alphabetized using a mergesort algorithm */ /* List nodes */ struct node_t { struct node_t *next; struct node_t *prev; char *string; }; /* * Frees an entire list of node_t's * list is a pointer to any node in the list. */ void free_list(struct node_t *list); /* * Returns the number of nodes in the node_t list * list is a pointer to any node in the list. */ int get_count(struct node_t *list); /* * list is a pointer to any node in the list. * Returns the head of the node_t list. * Returns NULL if list is NULL. */ struct node_t *get_head(struct node_t *list); /* * list is a pointer to any node in the list. * Returns the tail of the node_t list. * Returns NULL if list is NULL. */ struct node_t *get_tail(struct node_t *list); /* * Returns a node_t list of the files and directories in directory dir_path * Ignores files or directories beginning with '.' * Returns the head of the list upon success, NULL upon failure */ struct node_t *get_dir_list(char *dir_path); /* * Adds a new node to the end of the node_t list list. * list is a pointer to any node in the list. * If list is NULL, a new node is created. * Places str in the new node. * Returns a pointer to the tail upon success, NULL upon failure. * If you create a list, it is your responsibility to free it with free_list() */ struct node_t *append_string(struct node_t *list, char *str); /* * Alphabetizes a list of node_t's according to ascii * head must be the head of the list * Returns a pointer to the head of the alphabetized list * You must free the list after you are finished * with it with free_list() */ struct node_t *alpha_mergesort(struct node_t *head); /* * Merges and alphabetizes (according to ascii) 2 node_t lists. * Typically only called by alpha_mergesort() */ struct node_t *alpha_merge(struct node_t *head1, struct node_t *head2); /* * Divides a node_t list in half, returning a * pointer to the second half. * head must be the head of the list */ struct node_t *divide_list(struct node_t *head);