| 
 | 
 
 
 楼主 |
发表于 2014-4-20 22:52:36
|
显示全部楼层
 
 
 
青玄 发表于 2014-4-20 21:17  
这个程序编译没问题啊!  
#include <stdio.h> 
#include <stdlib.h> 
#include<malloc.h> 
#include <iostream> 
using namespace std; 
typedef struct Node 
{        int data; 
struct Node *next; 
 
}NODE , *PNODE; 
typedef struct Stack 
{ 
        PNODE ptop; 
        PNODE pbottom; 
 
}STACK,*PSTACK; 
void InitStack(PSTACK  PS);                                                                 
        bool StackEmpty(PSTACK  PS); 
        void Push(PSTACK  PS, char newelem); 
        char Pop(PSTACK  PS); 
        void PrintStack(STACK  S); 
void main() 
{ 
        STACK  S; 
        char exp[80]; 
        char ch; 
        bool status; 
        int i; 
         
        cout<<"  输入要检验括号匹配的表达式:"<<endl; 
        cin>>exp; 
        InitStack(&S); 
        status=true; 
        i=0; 
        ch=exp[i]; 
        i++; 
        while ((ch!='\0') && status)        //回车换行符 
        { 
                switch (ch) 
                { 
                case '(': 
                 
                        Push(&S,ch); 
                        break; 
                case ')': 
                        if (Pop(&S)!='(') 
                                status=false; 
                        break; 
                 
                 
                } 
                ch=exp[i]; 
                i++; 
        } 
        if (StackEmpty(&S) && status) 
                cout<<"表达式正确!"<<endl; 
        else 
        { 
                cout<<"表达式不正确!"<<endl; 
                cout<<"第"<<i<<"字符开始不正确!"<<endl; 
        } 
        system("pause"); 
} 
void InitStack(PSTACK  S) 
{ 
        S->ptop=NULL; 
} 
bool StackEmpty(PSTACK  S) 
{ 
        if (S->ptop==NULL) 
                return true; 
        else 
                return false; 
} 
void Push(PSTACK  S, char newelem) 
{ 
        S->ptop++; 
        S->ptop->data=newelem; 
} 
char Pop(PSTACK  S) 
{ 
        S->ptop--; 
        return S->pbottom; 
} |   
 
 
 
 |