?? initpush.java
字號:
class InitPush {
StackProcess.Union[] ak=new StackProcess.Union[100];
int counter=0;
NsProcess ns;
InitPush(String s)
{ ns=new NsProcess(s);
ns.process();}
void process()
{ StackProcess sp1=new StackProcess();
for(int i=0;i<ns.sp.top;i++)
{ if(ns.sp.stack[i].type==0)
{ak[counter]=ns.sp.stack[i];counter++;continue;}
if(ns.sp.stack[i].value==')')
{
while(sp1.stack[sp1.top-1].value!='(')
{ak[counter]=sp1.pop();counter++;}
sp1.pop();continue;}
if(ns.sp.stack[i].value=='(')
sp1.push(ns.sp.stack[i]);
else{if(sp1.empty())
{ sp1.push(ns.sp.stack[i]);continue;}
if(sp1.stack[sp1.top-1].value=='('){sp1.push(ns.sp.stack[i]);continue;}
if(scale(ns.sp.stack[i])>scale(sp1.stack[sp1.top-1]))
{sp1.push(ns.sp.stack[i]); } //System.out.println(sp1.stack[sp1.top-1].value);
else{ int ff=sp1.top;for(int p=0;p<ff;p++){System.out.println("???????"+sp1.top);if(scale(ns.sp.stack[i])<=scale(sp1.stack[sp1.top-1])) {ak[counter]=sp1.pop();counter++;}}sp1.push(ns.sp.stack[i]);
}}
}
while(sp1.top!=0)
{ ak[counter]=sp1.pop();counter++;}
}
int scale(StackProcess.Union spu)
{ int i=0;
switch(spu.value)
{case '+':
case '-':i=1;break;
case '*':
case '/':
case '%':i=2;break;
case '^':i=3;break;
case '\1':
case '\2':
case '\3':
case '\4':
case '\5':
case '\6':
case '\7':
case '!':
case '\u0008':i=4;break;
case '(':i=5;}
return i;
}
public static void main(String[] args)
{ InitPush ip=new InitPush("2*3^2+3");
ip.process();
for(int i=0;i<10;i++)
{ System.out.println("sfsdf"+ip.ak[i].value);
System.out.println(ip.ak[i].valuekkk);}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -