中缀表达式转换成后缀表达式,包括加减乘除,c语言编程
发布网友
发布时间:2022-05-27 19:16
我来回答
共2个回答
热心网友
时间:2023-11-21 22:35
#include<stdio.h>
#include<stdlib.h>
typedef struct astack *Stack;
typedef struct astack
{
int top;
int maxtop;
char* data;
}Astack;
Stack NewEmpty(int size)
{
Stack S=(Stack)malloc(sizeof(Astack));
S->maxtop=size;
S->top=-1;
S->data=(char*)malloc(size*sizeof(char));
return S;
}
int StackEmpty(Stack S)
{
return S->top<0;
}
int StackFull(Stack S)
{
return S->top==S->maxtop;
}
int Peek(Stack S)
{
return S->data[S->top];
}
void Push(char x,Stack S)
{
if(StackFull(S))
{
printf("Stack is full!\n");
exit(1);
}
else
S->data[++S->top]=x;
}
int Pop(Stack S)
{
if(StackEmpty(S))
{
printf("Stack is empty!\n");
exit(1);
}
else
return S->data[S->top--];
}
Stack NewStack(int size)
{
Stack S=NewEmpty(size);
int i,x,num;
printf("Please enter the number of data:\n");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("Please enter the %d date:\n",i+1);
scanf("%c",&x);
Push(x,S);
}
return S;
}
void ShowStack(Stack S)
{
int i;
for(i=0;i<=S->top;i++)
{
printf(" %c",S->data[i]);
}
printf("\n");
}
热心网友
时间:2023-11-21 22:36
复合表达式吗追问嗯