为什么总提示v是未声明的标识符
#include<iostream>usingnamespacestd;template<classT>classsq_stack{private:intmm;intto...
#include<iostream>
using namespace std;
template<class T>
class sq_stack
{ private:
int mm;
int top;
T *v;
T *w;
public:
sq_stack(int);
void push(sq_stack,T);
void pop(sq_stack,T);
int pd();
};
template<class T>
sq_stack<T>::sq_stack(int m)
{ mm=m;
v=new T[mm];
w=new T[mm];
top=0;
return;
}
template<class T>
void sq_stack<T>::push(sq_stack v,T x)
{ cin>>x;
if(top==mm){
cout<<"stack overflow!"<<endl;
return;}
top=top+1;
v[top-1]=x;
return;
}
template<class T>
void sq_stack<T>::pop(sq_stack v,T y)
{
if(top==0)
{ cout<<"stack underflow!"<<endl;}
y=v[top-1];
top=top-1;
return(y);
}
template<class T>
int sq_stack<T>::pd()
{ int i,n;
char b[100];
n=0;
while(n!=top){pop(*v,b[n]);n++;}
for(i=0;i<n;i++){
push(*w,b[i]);
if(v[i]==w[i]) return 1;
else return 0;
}
}
int main()
{ sq_stack<char> s(100);
char a;
int count=0;
cin>>a;
while(a!='@')
{ s.push(*v,a);
count++;
cin>>a;}
if(count>10) cout<<"error"<<endl;
if(s.pd()==1) cout<<"该序列为回文序列!"<<endl;
else cout<<"该序列不是回文序列!"<<endl;
return 0;
} 展开
using namespace std;
template<class T>
class sq_stack
{ private:
int mm;
int top;
T *v;
T *w;
public:
sq_stack(int);
void push(sq_stack,T);
void pop(sq_stack,T);
int pd();
};
template<class T>
sq_stack<T>::sq_stack(int m)
{ mm=m;
v=new T[mm];
w=new T[mm];
top=0;
return;
}
template<class T>
void sq_stack<T>::push(sq_stack v,T x)
{ cin>>x;
if(top==mm){
cout<<"stack overflow!"<<endl;
return;}
top=top+1;
v[top-1]=x;
return;
}
template<class T>
void sq_stack<T>::pop(sq_stack v,T y)
{
if(top==0)
{ cout<<"stack underflow!"<<endl;}
y=v[top-1];
top=top-1;
return(y);
}
template<class T>
int sq_stack<T>::pd()
{ int i,n;
char b[100];
n=0;
while(n!=top){pop(*v,b[n]);n++;}
for(i=0;i<n;i++){
push(*w,b[i]);
if(v[i]==w[i]) return 1;
else return 0;
}
}
int main()
{ sq_stack<char> s(100);
char a;
int count=0;
cin>>a;
while(a!='@')
{ s.push(*v,a);
count++;
cin>>a;}
if(count>10) cout<<"error"<<endl;
if(s.pd()==1) cout<<"该序列为回文序列!"<<endl;
else cout<<"该序列不是回文序列!"<<endl;
return 0;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询