数据结构经典背包问题

上传人:豆浆 文档编号:4725270 上传时间:2017-08-23 格式:DOC 页数:6 大小:34KB
返回 下载 相关 举报
数据结构经典背包问题_第1页
第1页 / 共6页
数据结构经典背包问题_第2页
第2页 / 共6页
数据结构经典背包问题_第3页
第3页 / 共6页
数据结构经典背包问题_第4页
第4页 / 共6页
数据结构经典背包问题_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《数据结构经典背包问题》由会员分享,可在线阅读,更多相关《数据结构经典背包问题(6页珍藏版)》请在金锄头文库上搜索。

1、#include #include #define size 20struct stacksint datasize;int top;stack;void main()int wsize;int V;int k=0;int i=0;int j=1;int number;int s=0;printf(n 请输入可供选择装入物品的个数:);scanf(%d,&number);printf(n 请输入各件物品的体积:);for(i=0;is)printf(n 输入背包体积错误);printf(n);for(i=0;i0&k=wk)stack.datastack.top=k;stack.top+;V-

2、=wk;k+;if(V=0)printf(第%d 个符合条件的解:,j);for(i=0;iusing namespace std;bool IsOperator(char ch)char ops = +-*/;for (int i = 0; i st;len = strlen(inFix);for (int i = 0; i = 0)postFixj+ = st.top(); st.pop();st.push(c);while (st.empty() = false)postFixj+ = st.top();st.pop();postFixj = 0;/ 后缀表达式求值程序double po

3、stFixEval(char* postFix)stack st;int len = strlen(postFix);char c;for (int i = 0; i len; i+)c = postFixi;if (IsOperator(c) = false)st.push(c - 0);elsechar op1, op2;int val;op1 = st.top();st.pop();op2 = st.top();st.pop();switch (c)case +:val = op1 + op2; break;case -:val = op2 - op1;break;case *:val

4、= op1 * op2;break;case /:val = op2 / op1;break;st.push(val);return st.top();int _tmain(int argc, _TCHAR* argv)char inFix100;char postFix100;double val;while (1)printf(enter an expression:);gets_s(inFix);if (strlen(inFix) = 0)continue;printf(n%s = , inFix);inFix2PostFix(inFix, postFix);printf(%s = , postFix);val = postFixEval(postFix);printf(%.3fn, val);return 0;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号