📄 huiwen.cpp
字号:
#include<iostream.h>
#define max 30
typedef char datetype;
typedef struct stact{
datetype date[max];
int top;
}linkstact;
typedef struct row {
datetype date[max];
int tou ,wei ;
}linkrow;
int emptyrow (linkrow *s) //检查是否是空队列
{
if(s->tou == s->wei ) return 1;
else return 0;
}
linkrow *setNULLrow() //设置一个空队列
{
linkrow *s = new linkrow ;
s->tou = 0;
s->wei = 0;
return s;
}
datetype outtou(linkrow *s) //显示队列中的对头数据
{
if(emptyrow (s)) return 0;
else return (s->date [s->tou +1]);
}
linkrow * inrow(linkrow *s ,datetype x)// 入队列
{
if((s->wei+1)%max == s->tou ) return s;
s->wei = (s->wei +1)%max;
s->date [s->wei ] = x;
return s;
}
datetype outrow (linkrow *s) //出队列
{
if(emptyrow(s)) { cout<<"队列已经为空!"<<endl; return 0;}
s->tou = (s->tou +1)%max;
return (s->date [s->tou ]);
}
linkstact *setNULLstact(){ //设置一个空栈
linkstact *s = new linkstact;
s->top = -1;
return s;
}
int emptystact(linkstact *s) //检查是不是空栈
{
if( s->top == -1) return 2;
else return 0;
}
linkstact * instact (linkstact *s ,datetype x){//入栈 如果要上溢就返回NULL 则返回新的指针
if(s->top >= max-1) return NULL;
s->top ++;
s->date [s->top ] = x;
return s;
}
datetype outstact (linkstact *s){ // 出栈
if (emptystact(s)) return 0;
s->top --;
return s->date [s->top+1 ];
}
int panduan(linkstact *Astact ,linkrow *Arow)
{
while (!emptyrow(Arow))
if(outrow(Arow) != outstact(Astact))
return 0;
return 1;
}
void main ()
{
cout<<" 本程序是用来判断输入的字符串是不是回文~!"<<endl;
cout<<endl;
linkrow *Arow = setNULLrow();
linkstact *Astact = setNULLstact();
char string1[max];
cout<<"输入字符串:";
cin>>string1;
int i=0;
while(string1[i] !='\0')
{ Arow = inrow(Arow,string1[i]);
Astact = instact(Astact,string1[i]);
i++;
}
if(panduan(Astact,Arow))
cout<<"是回文!"<<endl;
else cout<<"不是回文!"<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -