?? 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 + -