📄 hxixun.c
字号:
include<LINE.h>
include<queue.h>
include<stack.h>
include<stdio.h>
void main()
{ char choice;
char ch;
ch='y';
while (ch=='y' || ch=='Y')
{
printf("\n\n\n");
printf("\n\t\t shu ju jie gou yan shi xi tong ");
printf("\n\t\t zhu cai dan ");
printf("\n\t\t***********************************************");
printf("\n\t\t * 1------xian xin biao **");
printf("\n\t\t * 2------ zhan **");
printf("\n\t\t * 3------dui lie **");
printf("\n\t\t * 0------tui chu **");
printf("\n\t\t*************************************");
printf("\n\t\t qing xuan zhe cai dan hao(0----3):");
scanf("%c",&choice);
getchar();
switch(choice)
{
case '1':linelist();break;
case '2':stack();break;
case '3':dui();break;
defautlt:printf("cai dan xuan zhe cuo wu ,qing cong shu");
}
if(choice=='0')
{
ch='0';
}
}
}
}
void createlist()
{linknode *p;
linknode *s;
char x;
int z=1;
n=0;
head=(linknode *)malloc(sizeof(linknode));
p=head;
printf("\n\t\t qing zhu ge shu ru yi'x' wei jie shu biao zhi \n");
printf("\n");
while(z)
{
printf("\t\t shu ru yi ge zhi fu shuju bing an hui chu:");
scanf("%c",&x);
getchar();
if(x!='x')
{
s=(linknode *)malloc(sizeof(linknode));
n++;
s->data=x;
p->next=s;
s->next=NULL;
p=s;
}
else z=0;
}
}
void Inslist(int i,char x)
{linknode *s,*p;
int j=0;
p=head;
while(p!=NULL && j<i)
{ j++;
p=p->next;
}
if(p!=NULL)
{ s=(linknode *)malloc(sizeof(linknode));
s->data=x;
s->next=p->next;
p->next=s;
n++;
}
else
printf("\n\t\t xian xin biao wei kong huo chao chu \n");
}
void dellist(char x)
{ linknode *p,*q;
if(head==NULL)
{ printf("\n\t\t xian biao xia yi");
return ;
}
if(head->next==NULL)
{
printf("\n\t\t xian biao wei kong ");
return ;
}
q=head;
p=head->next;
while(p!=NULL && p->data!=x)
{q=p;
p=p->next;
}
if(p!=NULL)
{
q->next=p->next;
free(p);
n--;
printf("\n\t\t jie dian %c ying jing san chu!",x);
}
else
printf("\n\t\t baoqian mei you zhao dao");
}
void showlist()
{
linknode *p=head;
printf("\n\t\t xian xin biao xian shi shou you de yuan su:");
if(head->next==NULL || p==NULL)
printf("\n\t\t lian biao wei kong ");
else
{
printf("\n\t\t");
while(p->next!=NULL)
{
printf("%5c",p->next->data);
p=p->next;
}
}
}
void linelist()
{
int i,j=1;
char choice,x,t;
head==NULL;
while(j)
{
printf("\n");
printf("\n\t\t xian xin biao zi xi tong ");
printf("\n\t\t*************************************");
printf("\n\t\t* 1--------jian biao **");
printf("\n\t\t* 2--------cha ru **");
printf("\n\t\t* 3--------san chu **");
printf("\n\t\t* 4--------xian shi **");
printf("\n\t\t* 0--------tui chu **");
printf("\n\t\t************************************");
printf("\n\t\t qing xuan zhe cai dan hao(0---4) :");
scanf("%c",&choice);
getchar();
switch(choice)
{case '1':printf("\n\t\t*********** shu ru 'x' wan cheng jian shu jie biao ****************");
createlist();
break;
case '2':printf("\n\t\t input shu ru yao cha ru de wei zhi i,x:");
scanf("%d,%c",&i,&x);
Inslist(i,x);
break;
case '3':printf("\n\t\t nput shu ru yao san chu de yuan su ");
scanf("%c",&t);
dellist(t);
break;
case '4':showlist();
break;
default:break;
}
if(choice='0')
{j=0;
}
}
}
void Inqueue(linkqueue *q)
{int x;
queuenode *p;
p=(queuenode *)malloc(sizeof(queuenode));
printf("\n\t\t input shu ru yi ge zheng shu: ");
scanf("%d",&x);
getchar();
p->data=x;
p->next=NULL;
if(q->front==NULL)
q->front=p;
else
{ q->rear->next=p;
q->rear=p;}
if(p)
printf("\n\t\t %d jin dui cheng gong \n",x);
}
int outqueue(linkqueue *q,int *v)
{queuenode *p;
if(q->front==NULL)
return 0;
else
{p=q->front;
*v=p->data;
q->front=p->next;
if(q->front==NULL)
q->rear=NULL;
free(p);
return 1;
}
}
void showqueue(linkqueue *q)
{queuenode *p=q->front;
if(p==NULL)
printf("\n\t\t dui lie wei kong \n");
else
{ printf("\n\t\t dui lie zhong de yuan su wei: ");
while(p!=NULL)
{ printf("%3d",p->data);
p=p->next;
}
printf("\n");
}
}
void readfront(linkqueue *q)
{
if(q==NULL || q->front==NULL)
printf("\n\t\t dui lie wei kong meiyou dui shou yuan shu \n");
else
printf("\n\t\t dui shou yuan su wei: %4d\n",q->front->data);
}
void queue()
{linkqueue *q;
int i=1;
int *v;
char w='0';
char choice='0';
q=(linkqueue *)malloc(sizeof(linkqueue));
v=(int *)malloc(sizeof(int));
q->front=q->rear=NULL;
while(i)
{
printf("\n");
printf("\n\t\t dui lie zi xi tong ");
printf("\n\t\t ***********************************");
printf("\n\t\t * 1------jin zhan **");
printf("\n\t\t * 2------chu zhan **");
printf("\n\t\t * 3------dui tou yuan su **");
printf("\n\t\t * 4------xian shi **");
printf("\n\t\t * 0------tui chu **");
printf("\n\t\t ***********************************");
printf("\n\t\t qing xian zhe cai dan hao (1--4):");
scanf("%c",&choice);
getchar();
switch(choice)
{
case '1':Inqueue(q);
break;
case '2':
if(outqueue(q,v)==0)
printf("\n\t\t dui lie wei kong \n");
else
printf("\n\t\t chu duiyuan su wei: %d",*v);
break;
case '3':readfront(q);
break;
case '4':showqueue(q);
break;
default:break;
}
if(choice='0')
{i=0;
}
}
}
void main()
{ char choice;
char ch;
ch='y';
while (ch=='y' || ch=='Y')
{
printf("\n\n\n");
printf("\n\t\t shu ju jie gou yan shi xi tong ");
printf("\n\t\t zhu cai dan ");
printf("\n\t\t***********************************************");
printf("\n\t\t * 1------xian xin biao **");
printf("\n\t\t * 2------ zhan **");
printf("\n\t\t * 3------dui lie **");
printf("\n\t\t * 0------tui chu **");
printf("\n\t\t*************************************");
printf("\n\t\t qing xuan zhe cai dan hao(0----3):");
scanf("%c",&choice);
getchar();
switch(choice)
{
case '1':linelist();break;
case '2':stack();break;
case '3':dui();break;
defautlt:printf("cai dan xuan zhe cuo wu ,qing cong shu");
}
if(choice=='0')
{
ch='0';
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -