简单的逆波兰式 c语言

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define OK 1
#define ERROR 0
const int maxn = 20;

typedef struct Stack{
	int max_size, top_index;
	char *elements;
}Stack;

void init(Stack *s, int size){
	s->max_size = size;
	s->top_index = -1;
	s->elements = (char*)malloc(sizeof(char)*size);
}

int push(Stack *s, char value){
	if (s->top_index >= s->max_size - 1){
		return ERROR;
	}
	s->top_index++;
	s->elements[s->top_index]=value;
	return OK;
}

void pop(Stack *s){
	if (s->top_index <0){
		return;
	}
	s->top_index--;
}

int top(Stack *s){
	return s->elements[s->top_index];
}

void clear(Stack *s){
	free(s->elements);
	free(s);
}

int isOperator(char c){
	return (c == '+' || c == '-' || c == '*' || c == '/');
}

int priority(char c){
	if (c == '*' || c == '/'){
		return 2;
	}
	if (c == '+' || c == '-'){
		return 1;
	}
	else{
		return 0;
	}
}

int op(int a, int b, char c){
	int res;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值