From: Jordan B. <jor...@me...> - 2011-04-30 16:23:58
|
Below is the code I have thus far for my program. I am now in need of a method to sort this linked list alphabetically. The functioning that will handle this is "list_selection_sort()". Does any one have an Idea. I know that I could do it by copying each word from the linked list and sort them in an array and use a loop to link them all together but that is copying too much and using too many of the computers resources. I know there is a simple algortihm for this since the list is a linked list. #include <iostream> #include <cstdlib> #include <cstring> using namespace std; const int MAX_WORD_LENGTH = 80; /* definition of a node */ struct Node; typedef Node *Node_ptr; struct Node { char word[MAX_WORD_LENGTH]; Node_ptr ptr_to_next_node; }; /* Function to assign a linked list to "a_node" */ void assign_list(Node_ptr &a_list); /* Function to assign a new dynamic node variable to "a_node" */ void assign_new_node(Node_ptr &a_node); /* Function to print the strings in the list "a_node" */ void print_list(Node_ptr a_node); void add_after(Node_ptr &list, char a_word[], char word_after[]); //This function inserts a node containing "word_after" in the linked list "list", after the first occurrence of a node containing "a_word". If "list" does not contain such a node, the function leaves it unchanged. void delete_node(Node_ptr &a_list, char a_word[]); //This function deletes the first node in "a_list" which contains "a_word" |