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

📄

📁 表达式的求值!!!!数据结构.实现功能!
💻
字号:
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
using namespace std;

 struct calStack
{
	float *base;
	float *top;
	int stackSize;
		
};
bool initcalStack(calStack &S)
{
	S.base =(float *)malloc(STACK_INIT_SIZE*sizeof(float));
	if(!S.base) return false;
	S.top=S.base;
	S.stackSize=STACK_INIT_SIZE;
	return true;
}
bool pushNum(calStack &S,float e)
{
	if(S.top-S.base>=S.stackSize-1)
	{
		S.base =(float *)realloc(S.base,(S.stackSize+STACKINCREMENT)*sizeof(float));
		if(!S.base) return false;
		S.top =S.base +(S.stackSize -1);
		S.stackSize+=STACKINCREMENT;
	}
	*S.top=e;
	S.top+=1;
	
	return true;
}


bool popNum(calStack &S,float &e)
{
	if (S.base==S.top) return false;
	e=*--S.top;
	return true;
}



float getTopNum(calStack S)
{
	float e;
	if(S.base ==S.top) exit(1);
	e=*--S.top;
	return e;
}

float operate(float a,char theta,float b)
{
	switch(theta)
	{
	case '+':
		return a+b;
	case '-':
		return a-b;
	case '*':
		return a*b;
	case '/':
		return a/b;
	}
	exit (1);
}
float change(const char c,int i)  //  将第i为的数字字符转换为整数
{
	int j=1;
	while(i>1)
	{
		j*=10;
		i--;
	}
	switch(c)
	{
	case '0':
		return 0;
	case '1':
		return j;
	case '2':
		return j*2;
	case '3':
		return j*3;
	case '4':
		return j*4;
	case '5':
		return j*5;
	case '6':
		return j*6;
	case '7':
		return j*7;
	case '8':
		return j*8;
	case '9':
		return j*9;
	}
	exit(1);
}
			

⌨️ 快捷键说明

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