|
|
1鱼币
#include <iostream>
using namespace std;
typedef struct
{
char S[50]; /*用来存放栈中元素的一维数组*/
int top; /*用来存放栈顶元素的下标,top为-1表示空栈*/
}SeqStack;
int main()
{
char A[10];
int Prool(char A[10],int n);
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>A[i];
}
return 0;
}
int Prool(char A[10],int n)
{
int top=-1;int i=0; int flag=1; SeqStack S[50];
while(i<n && flag)
{
if( A[i]=='(' || A[i]=='[' )
S[++top] = A[i++];
else
{
switch (A[i])
{
case ')':
if( top== -1 || S[top--] != '(') flag=0;
break;
case ']':
if( top== -1 || S[top--] != '[') flag=0;
break;
}
}
i++;
}
return flag;
}
\C++练习本\括号.cpp(28) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'char' (or there is no acceptable conversion)
E:\C++练习本\括号.cpp(34) : error C2676: binary '!=' : 'SeqStack' does not define this operator or a conversion to a type acceptable to the predefined operator
E:\C++练习本\括号.cpp(37) : error C2676: binary '!=' : 'SeqStack' does not define this operator or a conversion to a type acceptable to the predefined operator
Error executing cl.exe.
括号.exe - 3 error(s), 0 warning(s)
|
最佳答案
查看完整内容
栈结构吧 首先 栈是一种特殊的链表
你要是学C++ 先做出个单向链表 然后继承就好了
自己添加个push pop方法 取链表的尾部和压入尾部
至于运算符重载
你的程序本身就有问题
SeqStack S[50];
S[++top] = A;
S为SeqStack 数组
S[++top] 返回的是SeqStack 对象
右边为char类型
一个对象=一个char类型 即使重载了 你能告诉我做什么运算
你对象里也不是定义的char 而是char数组
完全可以在你结构体加一个 =号重 ...
|