一、设计任务:
编写程序,采用基数排序方法将一组英文单词按字典排列,假设单词全由小写字母或者空格构成,最长的单词由Maxlen个字母。
二、源代码:
头文件:
#define MaxLen 9 //定义单词最大长度为9
class WordSort {
public:
typedef char Word[MaxLen + 1]; //定义长度为MaxLen的char型数组
typedef struct node
{
Word word; //数据域
struct node *next; //指针域
}LinkNode; //声明结构体类型
//静态方法
static void PreProcess(Word word[], int n); //单词预处理
static void EndProcess(Word word[], int n); //删除预处理中添加的空格
static void RadixSort(Word word[],int Radix, int n); //基数排序算法
static void DispWord(Word word[], int n); //输出单词
};
源文件:
#include "WordSort.h"
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int n =