200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > c语言未定义标识符using c++未定义标识符怎么办?

c语言未定义标识符using c++未定义标识符怎么办?

时间:2021-11-11 14:41:58

相关推荐

c语言未定义标识符using c++未定义标识符怎么办?

满意答案

lg254839555

.07.13

采纳率:57%等级:12

已帮助:8508人

#include

#include

using namespace std;

struct LinkNode{

char data;

struct LinkNode *link;

LinkNode(){int data=0;LinkNode *top=NULL;}

};

class LinkedStack{

private:

LinkNode *top;

int size;

public:

LinkedStack(){top = NULL ;};

~LinkedStack(){makeEmpty();};

void push(char x);

char pop();

bool makeEmpty();

int getSize();

bool getTop();

bool isEmpty();

};

void LinkedStack::push(char x){

LinkNode *newNode=new LinkNode;

newNode->data=x;

newNode->link=top;

top=newNode;

size++;

assert(top!=NULL); };

bool isEmpty(){

if(top == NULL)return true; //这里老是提示top为“未定义标识符”怎么办?

return false;

//return (top==NULL)?true:false;这种写法也提示出错

};

char LinkedStack::pop() {

char x;

if(isEmpty()==true){

cout<

return false;}

LinkNode *p=top;

top= top->link;

x=p->data;

delete p;

return x;

};

bool LinkedStack::makeEmpty(){ //使链表全部清空

LinkNode *p;

cout<

while(top!= NULL){p=top;top=top->link;delete p;}

cout<

return true;

};

int LinkedStack::getSize(){ //获得表的长度

LinkNode *p=top;

int k =0;

while(top!=NULL){

top=top->link; k++;

}

cout<

return k;

};

void main (){

LinkedStack lstack;

int n ;

cout<

cin>>n;

//char *p = new expression[100];

char expression[100];

cout<

for(int i=0;i

cin>>expression[i];

}

for(int j=0;j

if(expression[j] ==( '('||'{'||'[')){

lstack.push(expression[j]);

}

if(expression[j] == (')'||'}'||']')){

if( expression[j] == lstack.pop()){

cout<

}else{

cout<

}

}

}

while(lstack.isEmpty() == false){

int d = lstack.getSize();

cout<

cout<

for(int k=0;k<=d;k++){

lstack.pop();

}

}

lstack.makeEmpty();

system("Pause");

}

015分享举报

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。