| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5194 人关注过本帖
标题:如何使用堆栈法???
只看楼主 加入收藏
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 
我也申请了
可惜没有激活码

2005-04-12 09:08
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
我激活码有了。就是点进去他说确认码不存在。真火

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-12 09:14
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 

激活码哪里来的?


2005-04-12 09:36
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
以下是引用幻风幻云在2005-4-12 9:36:28的发言:

激活码哪里来的?

发到邮箱里来的。 我是两点多申请的,所以快点吧。


我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-12 09:48
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 

晚上回去弄

2005-04-12 10:00
leeteng
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2005-1-7
收藏
得分:0 
晕,我都回过三次了,怎么每次都没有啊!!
是不是让我写一下实现代码?
2005-04-12 19:27
leeteng
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2005-1-7
收藏
得分:0 

这个就是将表达式转化成逆波兰的实现代码,我从书上抄的 (JAVA版的).这个程序将例如(a+b)*c等等任意复杂的式子转化过来. ------> a b + c * public class InfixToPostfix { String ifx; String pfx;

public void convertToPostfix() { StackClass stack = new StackClass(100); int i; char stackOpr; CharElement temp;

i=0; pfx = "";

int len = ifx.length();

for(i = 0; i < len; i++) if(ifx.charAt(i) >= 'A' && ifx.charAt(i) <= 'Z') pfx = pfx + ifx.charAt(i); else { switch(ifx.charAt(i)) { case '(': stack.push(new CharElement(ifx.charAt(i))); break;

case ')': temp = (CharElement) stack.top(); stack.pop(); stackOpr = (char) temp.getChar();

while(stackOpr != '(') { pfx = pfx + stackOpr;

if(!stack.isEmptyStack()) { temp = (CharElement) stack.top(); stack.pop(); stackOpr = (char)temp.getChar(); } else break; } break; case ';': case ' ': break;

default: if(stack.isEmptyStack()) stack.push(new CharElement(ifx.charAt(i))); else { temp = (CharElement) stack.top(); stack.pop(); stackOpr = (char) temp.getChar();

while(precedence(stackOpr,ifx.charAt(i))) { pfx = pfx + stackOpr; if(!stack.isEmptyStack()) { temp = (CharElement)stack.top(); stack.pop(); stackOpr = (char) temp.getChar();

} else break; }

if(!precedence(stackOpr,ifx.charAt(i))) stack.push(new CharElement(stackOpr));

stack.push(new CharElement(ifx.charAt(i))); }

}//end switch }//end else

while(!stack.isEmptyStack()) { temp = (CharElement)stack.top(); stack.pop();

pfx += (char) temp.getChar();

}

}//end convertToPostfix

public boolean precedence(char opr1, char opr2) { int prec1 = 0, prec2 = 0;

if(opr1 == '*' || opr1 =='/') prec1 = 2; else if(opr1 == '+' || opr1 == '-') prec1 = 1; else if(opr1 =='(') prec1 = 0;

if(opr2 == '*' || opr2 == '/') prec2 = 2; else if(opr2 =='+' || opr2 == '-') prec2 = 1;

return(prec1 >= prec2); }//end precedence

public void getInfix(String data) { ifx = data; convertToPostfix(); }

public void showInfix() { System.out.println("Infix: " + ifx); }

public void showPostfix() { System.out.println("Postfix: " + pfx); }

public InfixToPostfix(String infx) { ifx = infx; convertToPostfix(); } }

2005-04-12 19:33
leeteng
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2005-1-7
收藏
得分:0 
你再实现一个StackClass 类就可以了.这个堆栈类是基于数组实现的,这个数组不能是单一的数据类型(因为式子里面既有字母,又有数字).而要可以压入这两种类型,并能很好的扩展.书上的实现是DataElement抽象类 然后CharElement类(int )和CharElement类(char)继承自抽象类.而StackClass类里面实现的数组是DataElement型的 DataElement[] list;
这样堆栈就可以压入这两种类型了---DataElement的子类(里氏带换).就像系统提供的Stack类 它的是Object类的.在这里没有必要,而且估计效率也不高.
2005-04-12 20:09
leeteng
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2005-1-7
收藏
得分:0 
这样你就能写主程序了 -- 伪代码:
  public class Test{
public stack void Main(){
1.提示输入式子.
2.调用上面的代码将式子转换过来 (1+3)*4  --- &gt; 1 3 + 4 *
3,将转换过来的式子 分割成单个字符.string.Split(' '); 装入一个数组,
4,从数组中取数,数字压栈,运算复出栈.
5, 打印结果.




2005-04-12 20:17
shiuly
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2005-4-7
收藏
得分:0 
好强,正在學習中....
麻煩大哥們在偶學習的時候8要說魔獸啊
弄的俺也想去撕殺了
2005-04-12 20:41
快速回复:如何使用堆栈法???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017382 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved