📄 zfqzuoyeq.c
字号:
#include <stdio.h>
struct stack
{
int data ;
struct stack*next ;
};
struct stack *top=NULL ;
void reverse() /*串的倒置*/
{
char s[50],t[50];
int i=0,j ;
printf("input strings\n");
scanf("%s",s);
while(s[i]!='\0')
{
i++;
}
i--;
for(j=0;i!=0;i--,j++)
t[j]=s[i];
t[j]=s[i];
printf("result:%s\n",t);
}
void connect() /*两个串的连接*/
{
char r[50],s[50],t[100];
int i,j ;
printf("input s1 and s2\n");
scanf("%s",r);
scanf("%s",s);
for(i=0;r[i]!='\0';i++)
t[i]=r[i];
for(j=0;s[j]!='\0';j++,i++)
t[i]=s[j];
t[i]='\0' ;
printf("result:\ns1:%s\ns2:%s\ns3:%s",r,s,t);
}
int pop(int*e) /*出栈*/
{
if(top!=NULL)
{
*e=top->data ;
top=top->next ;
}
else
{
printf("\nThere is no element");
return(1);
}
}
void push(int e) /*进栈*/
{
struct stack*p ;
p=(struct stack*)malloc(sizeof(struct stack));
p->data=e ;
p->next=top ;
top=p ;
}
void st()
{
char q ;
int c,m=0 ;
do
{
printf("\ninput number element of stack: ");
scanf("%d",&c);
push(c);
printf("\ndo you want to continue ? input Y/N");
q=getch();
}
while(q=='y'||q=='Y');
do
{
m=pop(&c);
if(m==1)
return ;
printf("\nthe top of the stack: %d",c);
printf("\ndo you want to continue ? input Y/N");
q=getch();
}
while(q=='y'||q=='Y');
}
main()
{
reverse();
connect();
st();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -