mathstack.java

来自「java 计算实现代码 利用堆栈实现 java 计算实现代码」· Java 代码 · 共 49 行

JAVA
49
字号
package org.yancan;

public class MathStack {
private int pointcounter;
private float[] stack=new float[100];
public MathStack() {
	  for(int i=0;i<stack.length;i++){
		  stringOperate s=new stringOperate();
		  stack[i]=s;
	  }
	  pointcounter=0;
}
public void push(float m){
	pointcounter++;
	if(pointcounter<stack.length){
		for(int i=pointcounter;i>0;i--){
			stack[i]=stack[i-1];
		}
		stack[0]=m;
	}else{
		System.out.println("the stack is full! please check out! thank you !");
	}
}
public float pop(){
	float r=-1;
	if(isEmpty()){
		System.out.println("the stack is empty! please check out! thank you !");
	}else{
		r=stack[0];
	if(pointcounter>0){
		for(int i=0;i<pointcounter;i++){
			stack[i]=stack[i+1];
		}
	 }
	}
	return r;
}
public float gettop(){
	return stack[0];
}
public boolean isEmpty(){
	if(pointcounter==0){
		return true;
	}else{
		return false;
	}
}
}

⌨️ 快捷键说明

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