⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mathstack.java

📁 java 计算实现代码 利用堆栈实现 java 计算实现代码
💻 JAVA
字号:
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++){
	  stack[i]=-1;
  }
  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -