急问程序问题

nalnait 2008-01-19 11:09:58
比如有: 9-8*7+(2+3*4)
怎样输出:
3*4
2+3*4
8*7+(2+3*4)
9-8*7+(2+3*4)


谢谢
...全文
66 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sjdev 2008-01-20
  • 打赏
  • 举报
回复
就这么点小程序还用MFC?

使用标准库的stack吧.如下例:
#pragma warning(disable:4786)
#include <stack>
#include <iostream>

using namespace std ;

typedef stack<int> STACK_INT;

void main()
{
STACK_INT stack1;

cout << "stack1.empty() returned " <<
(stack1.empty()? "true": "false") << endl; // Function 3

cout << "stack1.push(2)" << endl;
stack1.push(2);

if (!stack1.empty()) // Function 3
cout << "stack1.top() returned " <<
stack1.top() << endl; // Function 1

cout << "stack1.push(5)" << endl;
stack1.push(5);

if (!stack1.empty()) // Function 3
cout << "stack1.top() returned " <<
stack1.top() << endl; // Function 1

cout << "stack1.push(11)" << endl;
stack1.push(11);

if (!stack1.empty()) // Function 3
cout << "stack1.top() returned " <<
stack1.top() << endl; // Function 1

// Modify the top item. Set it to 6.
if (!stack1.empty()) { // Function 3
cout << "stack1.top()=6;" << endl;
stack1.top()=6; // Function 1
}

// Repeat until stack is empty
while (!stack1.empty()) { // Function 3
const int& t=stack1.top(); // Function 2
cout << "stack1.top() returned " << t << endl;
cout << "stack1.pop()" << endl;
stack1.pop();
}
}
nalnait 2008-01-20
  • 打赏
  • 举报
回复
在MFC中,有没有栈的类库呢?????
sjdev 2008-01-19
  • 打赏
  • 举报
回复
表达式求值.使用栈.
这是以前我们数据结构作业题.

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧