双向循环链表Word格式.docx
《双向循环链表Word格式.docx》由会员分享,可在线阅读,更多相关《双向循环链表Word格式.docx(19页珍藏版)》请在冰豆网上搜索。
ö
intinsert(LINKp2);
å
intdel(LINKp2,intm);
/*É
¾
voidcreat();
²
¢
½
Á
voidread();
/*¶
¡
Ä
¼
þ
Ú
Ý
voidwrite_fp();
/*Ð
/**********************************************************************/
voidexchange(LINKp1,LINKp2);
LINKcompare(LINKsp,chardn,chardm);
/*±
Ï
LINKbts(LINKsp,LINKp1,LINKp2,chardm);
/*´
Ó
ó
µ
Ð
Å
LINKstb(LINKsp,LINKp1,LINKp2,chardm);
chara;
FILE*fp;
LINKout_fp;
intd,num,menu;
/*menu²
Ë
¥
¿
Ø
Æ
if((fp=fopen("
C:
\\table.txt"
"
r"
))==NULL)/*´
ò
ª
{
printf("
Cannotopenthefile!
\nNowtheprogramwillbuildanewfile!
\n"
);
fp=fopen("
wt+"
creat();
out_fp=head;
do
{
fprintf(fp,"
%d%s%s%d%d\n"
out_fp->
data,out_fp->
name,\
out_fp->
tel,out_fp->
age,out_fp->
scoure);
out_fp=out_fp->
next;
}while(out_fp!
=head);
fclose(fp);
/*¹
}
else
read();
output(head);
/*************************************************************************************/
do
{
/*****Commandmenulist*****/\n1.Search\n2.Insert\n3.Delete\n4.Arrangement\n\
0.Exit\n"
/*Ö
÷
î
£
¬
Ò
É
Í
{
printf("
Pleaseselectanoption:
"
a=getch();
%c\n"
a);
if(a=='
1'
)
break;
elseif(a=='
2'
3'
4'
0'
exit
(1);
else
menu=1;
}while(menu);
/*********************************************/
if(a=='
chardm,dn;
Orderof(1.name2.scoure)?
:
dm=getch();
dm);
if((dm=='
)||(dm=='
))
Orderfrom(1.bigtosmall2.smalltobig)?
dn=getch();
dn);
if((dn=='
)||(dn=='
head=compare(head,dn,dm);
else
InvalidOptions!
}
else
output(head);
/************************************************/
Savetothefile?
(y/n):
y'
{
write_fp();
printf("
Savecomplete!
}
n'
read();
}while((a!
='
)&
&
(a!
));
Orderagain?
num=1;
{num=0;
menu=1;
}
}while(num);
read();
/************************************************************************************/
elseif(a=='
printf("
Pleaseentertheitemsyouwanttosearch:
\n\
(1.name2.tel3.age4.scoure):
Options:
/*fflush(stdin);
/*Ç
IO»
Ç
ø
d=getch();
d);
search(head,(char)d);
do
Searchagain?
a=getch();
if(a=='
num=1;
{num=0;
}while((a!
}while(num);
/****************************search********************************/
/**********************************************************************************/
Insertdata?
num=insert(head);
{num=0;
/***********************************************************************************/
{
whichnumberdoyouwanttodelete:
NO."
d=getch();
num=del(head,d);
output(head);
Deleteagain?
{
printf("
scanf("
%d"
&
d);
while((a=getchar())!
\n'
a!
=EOF);
/*Ë
Â
num=del(head,d);
output(head);
}
/****************************************************************************/
write_fp();
menu=0;
menu=1;
}while(menu);
exit
(1);
charsearch(LINKp,charn)/****************************²
********************************/
LINKa=p;
charb[9];
intc;
if((n=='
)||(n=='
Enterthecontent:
scanf("
%s"
b);
if((strcmp(a->
name,b)==0)||(strcmp(a->
tel,b)==0))
%3d.|%8s|%15s|%8d|%8d|\n"
a->
data,\
a->
name,a->
tel,a->
age,a->
return(0);
a=a->
}while(a!
=p);
NoData\n"
return(0);
elseif((n=='
c);
if((a->
age==c)||(a->
scoure==c))
return(0);
voidoutput(LINKsp)/********************************Ê
***********************************/
inti;
sp=head;
\nnum|name|tel|age|scoure|\n"
for(i=1;
;
i++)
sp->
data=i;
/****×
Ô
à
****/
sp->
sp->
name,sp->
tel,sp->
age,sp->
sp=sp->
if(sp==head)
break;
intinsert(LINKp2)/***************************²
****************************************/
LINKsp,newnode;
inti=0;
sp=p2->
front;
newnode=(LINK)malloc(sizeof(structlist));
if(newnode==NULL)
ERROR\n"
return
(1);
in_put(newnode);
newnode->
next=sp->
sp->
next->
front=newnode;
front=sp;
next=newnode;
insertcomplete!
return
(1);
intdel(LINKp2,intm)/*É
ã
LINKsp;
inta,i=0;
sp=p2;
i++;
while(sp!
if(m==1)
head=head->
if((1<
m)&
(m<
=i))
for(a=1;
a<
m;
a++)
sp=sp->
if((m>
i)||(m<
1))
outoforder\n"
front->
front=sp->
free(sp);
deletecomplete!
voidcreat()/*´
LINKpb,newnode;
for(i=0;
newnode=(LINK)malloc(sizeof(structlist));
{
newnode->
data=i+1;
in_put(newnode);
num|name|tel|age|scoure|\n"
newnode->
name,newnode->
tel,newnode->
age,newnode->
sure?
(press'
tocontinue):
/*·
À
¹
}while((a=getch())!
if(i==0)
{pb=head=newnode;
head->
front=NULL;
next=NULL;
}/*Ë
«
õ
{pb->
/*½
front=pb;
pb=newnode;
\nInsertagain?
if((a=getch())=='
continue;
break;
head->
pb->
next=head;
»
ê
voidread()/*¶
/*numÁ
fp=fopen("
fscanf(fp,"
newnode->
data,&
&
tel,&
age,&
pb=head=newnode;
}/*Ë
pb->
if(feof(fp))break;
head->
pb->
}
voidwrite_fp()/*Ð
if((fp=fopen("
))==NULL)/*Ð
LINKin_put(LINKp)/*Ê
pleaseinputthename:
scanf("
p->
name);
pleaseinputthetel:
tel);
pleaseinputtheage:
scanf("
age);
pleaseinputthescoure:
scanf("
return(p);
/****************************************************************************************/
LINKcompare(LINKsp,chardn,chardm)
LINKp1,p2,p0;
p1=p0=sp;
p2=p1->
if(dn=='
if(dm=='
for(;
p2!
=sp;
p2=p2->
next)
{
if(strcmp(p2->
name,p1->
name)>
0)
p1=p2;
}
sp=p1;
p0=sp;
(p0->
next)!
p0=p0->
p1=p0->
p2=p1->
for(;
if(p0->
next!
=p1)
exchange(p0,p1);