
急求C语言数据结构课程设计!!!!!
各位高手,小弟急求一份课程设计,题目是:编写一个基数排序算法,将一组英文单词按字典序排序,设最长的单词有n个字母。并且可查找到指定单词。谁知道请伸出援助之手,帮在下一把,...
各位高手,小弟急求一份课程设计,题目是:编写一个基数排序算法,将一组英文单词按字典序排序,设最长的单词有n个字母。并且可查找到指定单词。谁知道请伸出援助之手,帮在下一把,先谢谢了!!!
展开
2个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ML 500
struct node
{
char data[50];
struct node *lc,*rc;
};
char article[]={"Explosives, as we all know ,are things that can't get close to.Though it dosen't sound good,it plays an important part in our world.Nowadays ,almost everthing,is made using electricity.And coal is the most important resource to make electricity.Needless to say ,metal is taken from rocks.Regardless of coal or metal,we have to use explosives to get them.In a word,if we did't have explosives,we wouldn't have such a modern world."};
int offset=0;
struct node *tree,*root;
void inorder(struct node *ctree)
{
if(ctree->lc!=NULL)inorder(ctree->lc);
printf("%s ",ctree->data);
if(ctree->rc!=NULL)inorder(ctree->rc);
}
void AddIn(char word[])
{
int i=0,k; tree=root;
while(1)
{
i=0;k=strcmp(word,tree->data);
if(k<0)
{
if(tree->lc==NULL)
{
tree->lc=(struct node*)malloc(sizeof(struct node));
do
tree->lc->data[i]=word[i];
while(word[i++]!=0);
tree->lc->lc=NULL;tree->lc->rc=NULL;
break;
}
else tree=tree->lc;
}
else if(k>0)
{
if(tree->rc==NULL)
{
tree->rc=(struct node*)malloc(sizeof(struct node));
do
tree->rc->data[i]=word[i];
while(word[i++]!=0);
tree->rc->lc=NULL;tree->rc->rc=NULL;
break;
}
else tree=tree->rc;
}
else break;
}
}
void GetAWord(char temp[])
{
int i=0;
while((article[offset]<'A')|((article[offset]>'Z')&&(article[offset]<'a'))|(article[offset]>'z')&&article[offset]!=0)offset++;
while((article[offset]>='A')&&(article[offset]<='Z')|(article[offset]>='a')&&(article[offset]<='z'))
if (article[offset]!=0)
{
if((article[offset]>='A')&&(article[offset]<='Z'))
temp[i]=article[offset]+'a'-'A' ;
else temp[i]=article[offset];
i++;offset++;
}
else break;
temp[i]=0;
}
void main()
{
char word[500];int i=0;
root=(struct node *)malloc(sizeof(struct node));
root->lc=NULL;root->rc=NULL;
GetAWord(word);
do
root->data[i]=word[i];
while(word[i++]!=0);
while(1)
{
GetAWord(word);
if(word[0]==0)break;
AddIn(word);
}
inorder(root);
}
#include <stdlib.h>
#include <string.h>
#define ML 500
struct node
{
char data[50];
struct node *lc,*rc;
};
char article[]={"Explosives, as we all know ,are things that can't get close to.Though it dosen't sound good,it plays an important part in our world.Nowadays ,almost everthing,is made using electricity.And coal is the most important resource to make electricity.Needless to say ,metal is taken from rocks.Regardless of coal or metal,we have to use explosives to get them.In a word,if we did't have explosives,we wouldn't have such a modern world."};
int offset=0;
struct node *tree,*root;
void inorder(struct node *ctree)
{
if(ctree->lc!=NULL)inorder(ctree->lc);
printf("%s ",ctree->data);
if(ctree->rc!=NULL)inorder(ctree->rc);
}
void AddIn(char word[])
{
int i=0,k; tree=root;
while(1)
{
i=0;k=strcmp(word,tree->data);
if(k<0)
{
if(tree->lc==NULL)
{
tree->lc=(struct node*)malloc(sizeof(struct node));
do
tree->lc->data[i]=word[i];
while(word[i++]!=0);
tree->lc->lc=NULL;tree->lc->rc=NULL;
break;
}
else tree=tree->lc;
}
else if(k>0)
{
if(tree->rc==NULL)
{
tree->rc=(struct node*)malloc(sizeof(struct node));
do
tree->rc->data[i]=word[i];
while(word[i++]!=0);
tree->rc->lc=NULL;tree->rc->rc=NULL;
break;
}
else tree=tree->rc;
}
else break;
}
}
void GetAWord(char temp[])
{
int i=0;
while((article[offset]<'A')|((article[offset]>'Z')&&(article[offset]<'a'))|(article[offset]>'z')&&article[offset]!=0)offset++;
while((article[offset]>='A')&&(article[offset]<='Z')|(article[offset]>='a')&&(article[offset]<='z'))
if (article[offset]!=0)
{
if((article[offset]>='A')&&(article[offset]<='Z'))
temp[i]=article[offset]+'a'-'A' ;
else temp[i]=article[offset];
i++;offset++;
}
else break;
temp[i]=0;
}
void main()
{
char word[500];int i=0;
root=(struct node *)malloc(sizeof(struct node));
root->lc=NULL;root->rc=NULL;
GetAWord(word);
do
root->data[i]=word[i];
while(word[i++]!=0);
while(1)
{
GetAWord(word);
if(word[0]==0)break;
AddIn(word);
}
inorder(root);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询