这个是程序:
#include "string.h"
#define NULL 0
unsigned int key;
unsigned int key2;
int *p;
struct node
{
char name,address;
char num;
struct node *next;
}
**phone;
**nam;
**address;
typedef struct node *pnode;
typedef struct node *mingzi;
void hash(char num)
{
int i = 3;
key=(int)num;
while(num[i]!=NULL)
{
key+=(int)num[i];
i++;
key=key%17;
}
void hash2(char name)
{
int i = 1;
key2=(int)name;
while(name[i]!=NULL)
{
key2+=(int)name[i];
i++;
}
Key2=key2%17;
}
struct node* input()
{
struct node *temp=(struct node*)malloc(sizeof(struct node));
temp = new node;
temp->next=NULL;
printf("qing shu ru xing ming(no more then 8 chars) :\n");
scanf("%s",&temp->name);
printf"qing shu ru dian hua hao ma(no more then 11 numbers):\n");
scanf("%s",&temp->num);
printf("qing shu ru di zhi(no more then 20 chars):\n");
scanf("%s",&temp->address);
return temp;
}
int add()
{
struct node *newphone;
struct node *newname;
newphone=input();
printf("ni de ji lu shi");
if(find(newphone->num))
{
printf("hao ma yi jing cun zai bu nene zai tian jia.\n");
return 0;
}
if(find2(newphone->name))
{
printf("xing ming yi jing cun zai bu neng zai tian jia.\n");
return 0;
}
printf("%s_%s_%s\n",newphone->name,newphone->address,newphone->num);
newname=newphone;
newphone->next=NULL;
newname->next=NULL;
hash(newphone->num);
hash2(newname->name);
newphone->next = phone[key]->next;
phone[key]->next=newphone;
newname->next = nam[key2]->next;
nam[key2]->next=newname;
return 0;
}
int find(char num)
{
int isfind=0;
struct node *q;
hash(num);
node *q=phone[key]->next;
while(q!= NULL)
{
if(strcmp(num,q->num) ==0)
{
isfind=1;
break;
}
q=q->next;
}
if(isfind)
printf("%s_%s_%s\n",q->name,q->address,q->num);
return isfind;
}
int find2(char name)
{
int isfind=0;
hash2(name);
struct node *q=nam[key2]->next;
while(q!= NULL)
{
if(strcmp(name,q->name)==0)
{
isfind=1;
break;
}
q=q->next;
}
if(isfind)
printf("%s_%s_%s\n",q->name,q->address,q->num);
return isfind;
}
void create()
{
int i;
phone = (pnode*)malloc(13*sizeof(pnode));
for(i=0;i<13;i++)
{
phone[i]=(struct node*)malloc(sizeof(struct node));
phone[i]->next=NULL;
}
}
void create2()
{
int i;
nam = (mingzi*)malloc(13*sizeof(mingzi));
for(i=0;i<13;i++)
{
nam[i]=(struct node*)malloc(sizeof(struct node));
nam[i]->next=NULL;
}
}
void list()
{
int i;
struct node *p;
for(i=0;i<13;i++)
{
p=phone[i]->next;
while(p)
{
printf("%s_%s_%s\n",p->name,p->address,p->num);
p=p->next;
}
}
}
void list2()
{
int i;
struct node *p;
for(i=0;i<13;i++)
{
p=nam[i]->next;
while(p!=NULL)
{
printf("%s_%s_%s\n",p->name,p->address,p->num);
p=p->next;
}
}
}
void menu()
{
printf("0.tian jia ji lv.\n");
printf("2.cha zhao ji lu.\n");
printf("3.xing ming lie biao.\n");
printf("4.hao ma lie biao.\n");
printf("5.qing chu suo you ji lu.\n");
printf("6.tui chu xi tong.\n");
}
int main()
{
char num;
char name;
int sel;
create();
create2();
while(1)
{
menu();
scanf("%d",&sel);
if(sel==3)
{
char b;
printf("Input 9 to search with number,8 to name.\n");
b=getch();
if(b=='9')
{
printf("Please input the number:\n");
scanf("%s",#);
if(!find(num))
printf("Record not exist.\n");
}
else if(b=='8')
{
printf("Please input the name:\n");
scanf("%s",&name);
if(!find(name))
printf("Record not exist.\n");
}
else
{
printf("Wrong input!Please input again!\n");
continue;
}
}
else if(sel==2)
{
printf("All record with name:\n");
list2();
}
else if(sel==0)
{
printf("Please input the information:\n");
add();
}
else if(sel==4)
{
printf("All record with number:\n");
list();
}
else if(sel==5)
{
create();
create2();
printf("All records have been removed.\n");
}
else if(sel==6)
{printf("7");
break;
}
}
return 0;
}
虚拟运行,比较难,问题快过期了加分吧朋友!
//---------------------------------------------------------------------------
#include
#include
#define
DATASTYLE
"%d
"
/*结点数据成员的数据类型对应的格式控制符*/
typedef
int
datatype;
/*结点数据成员的数据类型*/
typedef
struct
node{
/*树结点的数据结构*/
datatype
data;
struct
node
*left,*right;
}
node;
node
*insert(node
*a,datatype
d)
/*将d插入到a指向的树中,返回插入元素后的树*/
{
node
*t=NULL;
if
(a==NULL)
{
/*如果当前树为空,就创建一个新结点*/
t=malloc(sizeof(node));
t->data=d;
t->left=t->right=NULL;
}
else
if
(d>a->data)
{
/*如果树不空,并且d大于当前结点,则将d插入到当前结点的右子树*/
a->right=insert(a->right,d);
t=a;
}
else
if
(d<=a->data)
{
/*如果树不空,并且d小于当前结点,则将d插入到当前结点的左子树*/
a->left=insert(a->left,d);
t=a;
}
return
t;
}
void
prttree(node
*r)
/*中序遍历输出排序二叉树*/
{
if
(r)
{
prttree(r->left);
printf(DATASTYLE,r->data);
prttree(r->right);
}
}
void
Free(node
*r)
/*利用后序遍历算法删除二叉树*/
{
if
(r)
{
Free(r->left);
Free(r->right);
free(r);
}
}
int
main(int
argc,
char*
argv[])
{
datatype
a={1,9,2,8,3,7,4,6,5,0};
int
i;
node
*root=NULL;
for
(i
=
0;
i
<
10;
i++)
/*将a数组中的10个整数插入到root二叉树中*/
{
printf(DATASTYLE,a[i]);
root=insert(root,a[i]);
}
putchar('\n');
prttree(root);
Free(root);
return
0;
}
//---------------------------------------------------------------------------
这个自己看下
不过是用C实现的
#include
#include
#include
#define
MAXSIZE
1000
typedef
char
datatype;
typedef
struct
{
datatype
a[MAXSIZE];
int
size;
}e_list;
e_list
s;
e_list
t;
void
ptint_slt(e_list
slt);
/*输出文本*/
void
letter_number(e_list
slt);
/*全部字母个数*/
void
space_number(e_list
slt);
/*全部空格个数*/
void
digit_number(e_list
slt);
/*全部数字总数*/
void
size_number(e_list
slt);
/*文章总字数*/
void
dele_print(e_list
p,e_list
slt);
/*输出删除某一字符串后的文章*/
void
ptint_slt(e_list
slt)
/*输出文本*/
{
int
i,j=0;
if(!slt.size)
{printf("\n错误!");exit(1);}
else
for(i=0;i{printf("%c",slt.a[i]);j++;if(j%20==0)printf("\n");}}voidletter_number(e_listslt)/*全部字母个数*/{inti,j=0;if(!slt.size){printf("\n错误!");exit(1);}elsefor(i=0;i{if((slt.a[i]>='a'&&slt.a[i]<='z')||(slt.a[i]>='A'&&slt.a[i]<='Z'))j++;}printf("%d",j);}voidspace_number(e_listslt)/*全部空格个数*/{inti,j=0;if(!slt.size){printf("\n错误!");exit(1);}elsefor(i=0;i{if(slt.a[i]=='')j++;}printf("%d",j);}voiddigit_number(e_listslt)/*全部数字总数*/{inti,j=0;if(!slt.size){printf("\n错误!");exit(1);}elsefor(i=0;i{if(slt.a[i]>='0'&&slt.a[i]<='9')j++;}printf("%d",j);}voidsize_number(e_listslt)/*文章总字数*/{printf("%d",slt.size);}voiddele_print(e_listp,e_listslt)/*输出删除某一字符串后的文章*/{inti,j,succ;i=0;succ=0;/*用i扫描正文t,succ为匹配成功标志*/while((i<=slt.size-p.size+1)&&(!succ)){j=0;succ=1;/*用j扫描模式p*/while((j<=p.size-1)&≻)if(p.a[j]==slt.a[i+j])j++;elsesucc=0;i++;}if(succ){for(j=0;j<(slt.size-p.size-1);j++){slt.a[i-1]=slt.a[i+p.size-1];i++;}slt.size=slt.size-p.size;for(i=0;i{printf("%c",slt.a[i]);}printf("\n");}elseprintf("\n错误!没有与字符串相配的子串!");}voidmain(){inti;intright;s.size=0;for(i=0;i{s.a[i]=getchar();s.size++;if(s.a[i]=='\n'){s.size--;break;}}printf("\n文本录入完毕!输出的文本为..\n");ptint_slt(s);printf("\n全部字母个数为:");letter_number(s);printf("\n全部空格个数为:");space_number(s);printf("\n全部数字个数为:");digit_number(s);printf("\n文章总字数为:");size_number(s);printf("\n要删除的字符串为:");for(i=0;i{t.a[i]=getchar();t.size++;if(t.a[i]=='\n'){t.size--;break;}}printf("\n删除字符串后的结果为:");dele_print(t,s);}阅读原文
{
printf("%c",slt.a[i]);
j++;
if(j%20==0)
printf("\n");
}
}
void
letter_number(e_list
slt)
/*全部字母个数*/
{
int
i,j=0;
if(!slt.size)
{printf("\n错误!");exit(1);}
else
for(i=0;i{if((slt.a[i]>='a'&&slt.a[i]<='z')||(slt.a[i]>='A'&&slt.a[i]<='Z'))j++;}printf("%d",j);}voidspace_number(e_listslt)/*全部空格个数*/{inti,j=0;if(!slt.size){printf("\n错误!");exit(1);}elsefor(i=0;i{if(slt.a[i]=='')j++;}printf("%d",j);}voiddigit_number(e_listslt)/*全部数字总数*/{inti,j=0;if(!slt.size){printf("\n错误!");exit(1);}elsefor(i=0;i{if(slt.a[i]>='0'&&slt.a[i]<='9')j++;}printf("%d",j);}voidsize_number(e_listslt)/*文章总字数*/{printf("%d",slt.size);}voiddele_print(e_listp,e_listslt)/*输出删除某一字符串后的文章*/{inti,j,succ;i=0;succ=0;/*用i扫描正文t,succ为匹配成功标志*/while((i<=slt.size-p.size+1)&&(!succ)){j=0;succ=1;/*用j扫描模式p*/while((j<=p.size-1)&≻)if(p.a[j]==slt.a[i+j])j++;elsesucc=0;i++;}if(succ){for(j=0;j<(slt.size-p.size-1);j++){slt.a[i-1]=slt.a[i+p.size-1];i++;}slt.size=slt.size-p.size;for(i=0;i{printf("%c",slt.a[i]);}printf("\n");}elseprintf("\n错误!没有与字符串相配的子串!");}voidmain(){inti;intright;s.size=0;for(i=0;i{s.a[i]=getchar();s.size++;if(s.a[i]=='\n'){s.size--;break;}}printf("\n文本录入完毕!输出的文本为..\n");ptint_slt(s);printf("\n全部字母个数为:");letter_number(s);printf("\n全部空格个数为:");space_number(s);printf("\n全部数字个数为:");digit_number(s);printf("\n文章总字数为:");size_number(s);printf("\n要删除的字符串为:");for(i=0;i{t.a[i]=getchar();t.size++;if(t.a[i]=='\n'){t.size--;break;}}printf("\n删除字符串后的结果为:");dele_print(t,s);}阅读原文
{
if((slt.a[i]>='a'&&slt.a[i]<='z')||(slt.a[i]>='A'&&slt.a[i]<='Z'))
j++;
}
printf("%d",j);
}
void
space_number(e_list
slt)
/*全部空格个数*/
{
int
i,j=0;
if(!slt.size)
{printf("\n错误!");exit(1);}
else
for(i=0;i{if(slt.a[i]=='')j++;}printf("%d",j);}voiddigit_number(e_listslt)/*全部数字总数*/{inti,j=0;if(!slt.size){printf("\n错误!");exit(1);}elsefor(i=0;i{if(slt.a[i]>='0'&&slt.a[i]<='9')j++;}printf("%d",j);}voidsize_number(e_listslt)/*文章总字数*/{printf("%d",slt.size);}voiddele_print(e_listp,e_listslt)/*输出删除某一字符串后的文章*/{inti,j,succ;i=0;succ=0;/*用i扫描正文t,succ为匹配成功标志*/while((i<=slt.size-p.size+1)&&(!succ)){j=0;succ=1;/*用j扫描模式p*/while((j<=p.size-1)&≻)if(p.a[j]==slt.a[i+j])j++;elsesucc=0;i++;}if(succ){for(j=0;j<(slt.size-p.size-1);j++){slt.a[i-1]=slt.a[i+p.size-1];i++;}slt.size=slt.size-p.size;for(i=0;i{printf("%c",slt.a[i]);}printf("\n");}elseprintf("\n错误!没有与字符串相配的子串!");}voidmain(){inti;intright;s.size=0;for(i=0;i{s.a[i]=getchar();s.size++;if(s.a[i]=='\n'){s.size--;break;}}printf("\n文本录入完毕!输出的文本为..\n");ptint_slt(s);printf("\n全部字母个数为:");letter_number(s);printf("\n全部空格个数为:");space_number(s);printf("\n全部数字个数为:");digit_number(s);printf("\n文章总字数为:");size_number(s);printf("\n要删除的字符串为:");for(i=0;i{t.a[i]=getchar();t.size++;if(t.a[i]=='\n'){t.size--;break;}}printf("\n删除字符串后的结果为:");dele_print(t,s);}阅读原文
{
if(slt.a[i]=='
')
j++;
}
printf("%d",j);
}
void
digit_number(e_list
slt)
/*全部数字总数*/
{
int
i,j=0;
if(!slt.size)
{printf("\n错误!");exit(1);}
else
for(i=0;i{if(slt.a[i]>='0'&&slt.a[i]<='9')j++;}printf("%d",j);}voidsize_number(e_listslt)/*文章总字数*/{printf("%d",slt.size);}voiddele_print(e_listp,e_listslt)/*输出删除某一字符串后的文章*/{inti,j,succ;i=0;succ=0;/*用i扫描正文t,succ为匹配成功标志*/while((i<=slt.size-p.size+1)&&(!succ)){j=0;succ=1;/*用j扫描模式p*/while((j<=p.size-1)&≻)if(p.a[j]==slt.a[i+j])j++;elsesucc=0;i++;}if(succ){for(j=0;j<(slt.size-p.size-1);j++){slt.a[i-1]=slt.a[i+p.size-1];i++;}slt.size=slt.size-p.size;for(i=0;i{printf("%c",slt.a[i]);}printf("\n");}elseprintf("\n错误!没有与字符串相配的子串!");}voidmain(){inti;intright;s.size=0;for(i=0;i{s.a[i]=getchar();s.size++;if(s.a[i]=='\n'){s.size--;break;}}printf("\n文本录入完毕!输出的文本为..\n");ptint_slt(s);printf("\n全部字母个数为:");letter_number(s);printf("\n全部空格个数为:");space_number(s);printf("\n全部数字个数为:");digit_number(s);printf("\n文章总字数为:");size_number(s);printf("\n要删除的字符串为:");for(i=0;i{t.a[i]=getchar();t.size++;if(t.a[i]=='\n'){t.size--;break;}}printf("\n删除字符串后的结果为:");dele_print(t,s);}阅读原文
{
if(slt.a[i]>='0'&&slt.a[i]<='9')
j++;
}
printf("%d",j);
}
void
size_number(e_list
slt)
/*文章总字数*/
{
printf("%d",slt.size);
}
void
dele_print(e_list
p,e_list
slt)
/*输出删除某一字符串后的文章*/
{
int
i,j,succ;
i=0;succ=0;
/*用i扫描正文t,succ为匹配成功标志*/
while((i<=slt.size-p.size+1)&&(!succ))
{
j=0;succ=1;
/*用j扫描模式p*/
while((j<=p.size-1)&≻)
if(p.a[j]==slt.a[i+j])
j++;
else
succ=0;
i++;
}
if(succ)
{
for(j=0;j<(slt.size-p.size-1);j++)
{
slt.a[i-1]=slt.a[i+p.size-1];
i++;
}
slt.size=slt.size-p.size;
for(i=0;i{printf("%c",slt.a[i]);}printf("\n");}elseprintf("\n错误!没有与字符串相配的子串!");}voidmain(){inti;intright;s.size=0;for(i=0;i{s.a[i]=getchar();s.size++;if(s.a[i]=='\n'){s.size--;break;}}printf("\n文本录入完毕!输出的文本为..\n");ptint_slt(s);printf("\n全部字母个数为:");letter_number(s);printf("\n全部空格个数为:");space_number(s);printf("\n全部数字个数为:");digit_number(s);printf("\n文章总字数为:");size_number(s);printf("\n要删除的字符串为:");for(i=0;i{t.a[i]=getchar();t.size++;if(t.a[i]=='\n'){t.size--;break;}}printf("\n删除字符串后的结果为:");dele_print(t,s);}阅读原文
{
printf("%c",slt.a[i]);
}
printf("\n");
}
else
printf("\n错误!没有与字符串相配的子串!");
}
void
main()
{
int
i;
int
right;
s.size=0;
for(i=0;i{s.a[i]=getchar();s.size++;if(s.a[i]=='\n'){s.size--;break;}}printf("\n文本录入完毕!输出的文本为..\n");ptint_slt(s);printf("\n全部字母个数为:");letter_number(s);printf("\n全部空格个数为:");space_number(s);printf("\n全部数字个数为:");digit_number(s);printf("\n文章总字数为:");size_number(s);printf("\n要删除的字符串为:");for(i=0;i{t.a[i]=getchar();t.size++;if(t.a[i]=='\n'){t.size--;break;}}printf("\n删除字符串后的结果为:");dele_print(t,s);}
{
s.a[i]=getchar();
s.size++;
if(s.a[i]=='\n')
{s.size--;
break;}
}
printf("\n文本录入完毕!输出的文本为..\n");
ptint_slt(s);
printf("\n全部字母个数为:");
letter_number(s);
printf("\n全部空格个数为:");
space_number(s);
printf("\n全部数字个数为:");
digit_number(s);
printf("\n文章总字数为:");
size_number(s);
printf("\n要删除的字符串为:");
for(i=0;i{t.a[i]=getchar();t.size++;if(t.a[i]=='\n'){t.size--;break;}}printf("\n删除字符串后的结果为:");dele_print(t,s);}
{
t.a[i]=getchar();
t.size++;
if(t.a[i]=='\n')
{t.size--;
break;}
}
printf("\n删除字符串后的结果为:");
dele_print(t,s);
}