圆括号匹配

#include "LinkStack.hpp"

#include <iostream>
using namespace std;

int main()
{
	LinkStack<char> stack;

	cout << "输入带括号的字符串 ((a)(b))" << endl;
	
	char ch;

	do
	{
		cin >> ch;
		
		switch(ch)
		{
			case '(': stack.Push(ch);
				break;
			case ')': 
				if(!stack.IsEmpty())
				{
					stack.Pop();
					break;
				}
				else
				{
					cout << "ERROR!" <<endl;
					return 0;
				}
		}
	}while(ch!='0'); // 回车 \r 换行 \n
	if(!stack.IsEmpty())
	{
		cout << "ERROR!" << endl;
		return 0;
	}
	else
	{
		cout << "OK!" << endl;	
		return 0;
	}

}

你可能感兴趣的:(圆括号匹配)