问题及代码:
设计一个基数排序的算法,将一组英文单词,按字典顺序排列。假设单词均由小写字母或空格构成,最长的单词有MaxLen个字母。
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define MaxLen 9 //单词的最大长度
#define Radix 27 //基数rd为27,分别对应' ','a',…'z'
typedef char String[MaxLen+1]; //定义String为字符数组类型
typedef struct node
{
String word;
struct node *next;
} LinkNode;
void DispWord(String R[],int n) //输出单词
{
int i;
printf(" ");
for (i=0; i<n; i++)
printf("[%s] ",R[i]);
printf("\n");
}
void PreProcess(String R[],int n)
//对单词进行预处理,用空格填充尾部至MaxLen长
{
int i,j;
for (i=0; i<n; i++)
{
if (strlen(R[i])<MaxLen)
{
for (j=strlen(R[i]); j<MaxLen; j++)
R[i][j]=' ';
R[i][j]='\0'