【文件属性】:
文件名称:数据结构-顺序表链表
文件大小:2KB
文件格式:C
更新时间:2013-04-21 14:42:33
顺序表。链表
比较基本的功能
#include
#include
#include
typedef struct node{
char d;
struct node *next;
} node;
node *findalpha(node *sor) /*提取字母*/
{
node *nea;
if (sor==NULL) {
return NULL;
}
else if (isalpha(sor->d)) {
nea=malloc(sizeof(node));
nea->d=sor->d;
nea->next=findalpha(sor->next);
}
else return findalpha(sor->next);
return nea;
}
node *finddigit(node *sor) /*提取数字*/
{
node *nea;
if (sor==NULL) {
return NULL;
}
else if (isdigit(sor->d)) {
nea=malloc(sizeof(node));
nea->d=sor->d;
nea->next=finddigit(sor->next);
}
else return finddigit(sor->next);
return nea;
}
node *findother(node *sor) /*提取其它字符*/
{
node *nea;
if (sor==NULL) {
return NULL;
}
else if (!isdigit(sor->d)&&!isalpha(sor->d)) {
nea=malloc(sizeof(node));
nea->d=sor->d;
nea->next=findother(sor->next);
}
else return findother(sor->next);
return nea;
}
int main(int argc, char* argv[])
{
node *a=NULL,*b,*st,*alpha,*digit,*other;
char c;
while ((c=getchar())!='\n') /*读取字符并建表*/
{
if (a==NULL) {
a=malloc(sizeof(node));
st=a;
a->d=c;
}
else{
b=malloc(sizeof(node));
b->d=c;
a->next=b;
a=b;
}
}
a->next =NULL;
a=st;
puts("\nAll:");
while (a!=NULL) /*输出所有字符*/
{
printf("%c",a->d);
a=a->next ;
}
alpha=findalpha(st);
digit=finddigit(st);
other=findother(st);
puts("\n\nLetter:");
while (alpha!=NULL)
{
printf("%c",alpha->d);
alpha=alpha->next ;
}
puts("\n\nDigit:");
while (digit!=NULL)
{
printf("%c",digit->d);
digit=digit->next ;
}
puts("\n\nOther:") ;
while (other!=NULL)
{
printf("%c",other->d);
other=other->next ;
}
return 0;
}