[Dev-C++] Sort Linked List Alphabetically
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jordan B. <jor...@me...> - 2011-04-30 16:30:52
|
Here is my code thus far. I need a algorithm for the function that sorts the list( it is the very last function). I know there is a simple way to do this since it is a linked list. Any help I would gratefully welcome.
#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" |