void add()
{
struct address *info;
for (;;){
info=(struct address *)malloc(sizeof(list_entry));
if (!info){
printf("\nout of memory");
return;
}
inputs("\nName:",info->name,15);
if (!info->name[0]) break;
inputs("Street:",info->street,15);
inputs("City:",info->city,15);
inputs("State:",info->state,15);
inputs("Eip:",info->eip,15);
start=dls_store(info,start);
}
}
inputs(char *prompt,char *s,int count)
{
char p[255];
do{
printf(prompt);
gets(p);
if (strlen(p)>count) printf("\ntoo long\n");
}while (strlen(p)>count);
strcpy(s,p);
}
struct address *dls_store(struct address *i,struct address *top)
{
struct address *old,*p;
if (last==NULL){
i->next=NULL;
i->prior=NULL;
last=i;
return i;
}
p=top;
old=NULL;
while(p){
if (strcmp(p->name,i->name)<0){
old=p;p=p->next;
}
else{
if(p->prior){
p->prior->next=i;
i->next=p;
i->prior=p->prior;
p->prior=i;
return top;
}
i->next=p;
i->prior=NULL;
p->prior=i;
return i;
}
}
old->next=i;
i->next=NULL;
i->prior=old;
last=i;
return start;
}
delete()
{
struct address *info;
char s[80];
printf("\nInput name(delete):");
gets(s);
info=find(s);
if (info) {
if (start==info){
start=info->next;
if (start)
start->prior=NULL;
else
last=NULL;
}
else{
info->prior->next=info->next;
if(info!=last)
info->prior->next=info->prior;
else
last=info->prior;
}
free(info);
上一页 [1] [2] [3] [4] [5] [6] 下一页