[Dev-C++] Sorting Linked Lists and Array Members
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Jordan B. <jor...@me...> - 2011-05-02 02:48:07
|
Hey Everyone, I have the following function that I am implementing within a list class in order to be able to sort them. This list should sort the char array elements by the alphabet but so far have had little luck to implement this. At this point I know that I cannot compare the two values of the array with the ">" operand but if I type cast it to an int but then I also get the lowercase ASCII value for each letter and make it a constant to figure out which one goes first I could do it this way but there has to be an easier way to do this. Below I have pasted the entire program as to make it easier to understand the context of the function, the function in question is the very last one named "list_selection_sort". Any idea or comments would be much appreciated. Thanks, Jordan <code> void list_selection_sort(Node_ptr &a_list) { Node_ptr currNode; Node_ptr nextNode; Node_ptr lastNode; int itiems = 1; currNode = a_list; while(currNode ->ptr_to_next_node != NULL) { currNode = currNode ->ptr_to_next_node; itiems++; } lastNode = currNode; currNode = a_list; nextNode = currNode ->ptr_to_next_node; while (itiems > 0) { if(currNode -> word[0] > nextNode -> word[0]) { curr } else { lastNode = currNode; currNode = currNode ->ptr_to_next_node; nextNode = currNode ->ptr_to_next_node;} itiems--; } system("pause"); } <\code> |