سلام
من قبلا این برنامه رو برای استادمون نوشتم البته به دو صورت نوشتم ببین به دردت میخوره
#include <ctype.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#define SIZE 21
class stack
{
public :
stack();
empty();
void push(int);
int pop(void);
int top() const;
private:
int item[SIZE];
int mytop;
};
inline stack :: stack() {mytop = -1;}
inline stack :: empty() {return mytop = -1;}
void stack :: push(int x)
{
if (mytop == SIZE)
printf("Stack is full\n");
else
item[mytop++] = x;
}
int stack :: pop(void)
{
if (mytop == -1) {
printf("Stack is empty\n");
exit(1);
return 0;
}
return item[--mytop];
}
int stack :: top() const { if(mytop >= 0) return item[mytop]; }
//************************************************** **********
/*--------------------------------------------------------------------------
void intopost(const char *infix, char *postfix)
{
int st;
stack s;
s.push('(');
while (*infix != '\0') {
if (isspace(*infix)) {
;
}
else if (isalpha(*infix)) {
*postfix++ = *infix;
}
else if (*infix == '(') {
s.push('(');
}
else if (*infix == ')') {
while ((st = s.pop()) != '(')
*postfix++ = st;
}
else if (*infix == '*' || *infix == '/') {
while (1) {
if ((st = s.pop()) == '(' || st == '+'
|| st == '-') {
s.push(st);
break;
}
*postfix++ = st;
}
s.push(*infix);
}
else if (*infix == '+' || *infix == '-') {
while (1) {
if ((st = s.pop()) == '(') {
s.push(st);
break;
}
*postfix++ = st;
}
s.push(*infix);
}
else {
printf("Unknown input character %c\n", *infix);
}
++infix;
continue;
}
while ((st = s.pop()) != '(')
*postfix++ = st;
*postfix = '\0';
}
به صورتهای دیگه هم می توان نوشت