⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mowang.cpp

📁 VC++编的数据结构 魔王语言解释,可以输入多对括号,已经在VC编译通过
💻 CPP
字号:
#include<iostream>
#include<string>
#include<cstring>
#include"SqStack.h"
#include"SqQueue.h"
using namespace std;

void read_language(SqStack &S)
{   int n;
    string m; 
	cout<<"请输入魔王语言:"<<endl;
	cin>>m;
	n=m.length();//求字符串长度
	for(int i=n-1;i>=0;i--)
	{
		S.push(m[i]);
	}
}

void push_and_pop(SqStack &S1,SqStack &S2)
{
	char e,e1;
	SqStack S3;
	SqStack();
	while(!S1.StackEmpty())
	{   S1.pop(e);
 		if(e=='(')
		{
			S1.pop(e);
			e1=e;
			if(e!=')')S1.pop(e);
 			while(e!=')')
 			{
 				S3.push(e);      
 				S1.pop(e);
 			} 
			while(!S3.StackEmpty())
			{
			    S2.push(e1);
			    S3.pop(e);
			    S2.push(e);
			}
			S2.push(e1);
		}
	}
}//处理规则2

	
int main()
{
	char e,e1;
	SqStack S ;
	SqStack S1;
	SqStack S2;
	SqQueue Q;
	SqStack();
	SqQueue();
    read_language(S);//读入魔王语言
	while(!S.StackEmpty())
	{
		S.pop(e);
		if(e==')')
		{
			S1.push(e);
			S2.pop(e);
			while(e!='(')
			{
				S1.push(e);
				S2.pop(e);
			}
			if(e=='(')
				S1.push(e);
			push_and_pop(S1,S2);
		}
		else
			S2.push(e);
	}
	while(!S2.StackEmpty())
	{
		S2.pop(e);
		S.push(e);
	}

	while(!S.StackEmpty())
	{   S.pop(e);
 		if(e=='A')
			Q.EnQueue_A();
 		if(e=='B')
			Q.EnQueue_B();
		else
			Q.EnQueue(e);
	}
	cout<<"魔王语言可以解释为:"<<endl;
	Q.OutQueue();
	cout<<endl;
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -