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

📄 main.cpp

📁 数据结构中有关栈的知识
💻 CPP
字号:
#include "main.h"
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
	
	ofstream outfile("f1.dat",ios::out);
	if(! outfile) cout<<"打开错误"<<endl;
	char p[100];
	int m=0;
	cout<<"输入完以后 以'#&'结束"<<endl;
	for(int i=0;i<100;i++)
	{
		cin>>p[i];
		if(p[i]=='&'){cout<<"输入结束"<<endl; outfile<<p[i]; break;}
		else 
		outfile<<p[i];
	}
	outfile.close();
	cout<<"文件创建成功"<<endl;




	ifstream infile("f1.dat",ios::in);
    if(! infile) cout<<"打开错误"<<endl;
	else cout<<"打开成功"<<endl;


	seqstack l;
	l.top->data='#';
	char ch,ch1,op;
	infile>>ch;
	while(ch!='&')
	{if(isdigit(ch))  {cout<<ch;infile>>ch;}
		else
		{
			l.gettop(ch1);
			if(isp(ch1)<icp(ch))
			{
				l.push(ch);infile>>ch;
			}
			else if(isp(ch1)>icp(ch))
			{
				l.pop(op);cout<<op;
			}
			else
			{
			    l.pop(op);
				if(op=='(') infile>>ch;
				else {cout<<endl;return 0;}
			}
		}
	}
	infile.close();
	return 0;
}

























	/*for(int i=0;;i++)
	{
		cout<<"--------------------------------------------------------------"<<endl;
		cout<<"请输入要选择的操作 1:建栈  2:进栈  3:出栈  4:输出栈  5:退出"<<endl;
		cout<<"--------------------------------------------------------------"<<endl;
		int m;
		cin>>m;
		switch(m)
		{
		    case 1:cin>>l;break;
			case 2:l.push();break;
			case 3:l.pop();break;
			case 4:cout<<l;break;
			case 5:return 0;
		}
	}
	return 0;
}
*/

⌨️ 快捷键说明

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