后缀表达式求值中的若干有关问题
后缀表达式求值中的若干问题。
既用char类型的,又要用float类型的Push(S, x);该怎么编写程序。
还有就是后面的问题应该怎么样去解决。
/*****************************************/
/**** stack.h ****/
/*****************************************/
# include <stdlib.h>
# ifndef NULL
# define NULL ((void*)0);
# endif
typedef char datatype;
typedef struct node{
datatype data;
struct node* next;
} stacknode,* slink;
void Clearstack(slink& top)
{
top=NULL;
}
int Emptystack(slink top)
{
if(top == NULL)
{
return (1);
}
else
{
return (0);
}
}
//..........
datatype Gettop(slink top)
{
return top-> data;
}
//ERROR
void Push(slink& top,datatype x)
{
slink p;
p=(slink)malloc(sizeof(stacknode));
p-> data=x;
p-> next=top;
top=p;
}
datatype Pop(slink& top)
{
datatype x;
slink p;
if(Emptystack(top))
{
return NULL;
}
else
{
x=top-> data;
p=top;
top=top-> next;
free(p);
return (x);
}
}
/*****************************************************/
/**** 表达式求值.cpp ****/
/*****************************************************/
# include "stack.h "
# include <iostream.h>
# include <string.h>
# include <ctype.h>
# include <stdlib.h>
# include <stdio.h>
# define TRUE 1;
# define FALSE 0;
# define OK 1;
# define ERROR 0;
typedef int Status;
//比较调用函数
Status Precede(char x,char y)
//x> =y;则此函数返回TRUE;否则返回FALSE;
{
if(x== '+ '||x== '- '&&y== '* '||y== '/ ')
{
return FALSE;
}
else
{
return TRUE;
}
}
void mid_post(char E[], char B[])
{
int i=0,j=0;
char x;
slink top;
Push(top, '# ');
do
{
x= E[i++];
if(x== '# ')
{
while(!Emptystack(top))
{
B[j++]=Pop(top);
}
}
else
{
if(isdigit(x))
{
B[j++]=x;
}
else
if(x== ') ')
{
while(Gettop(top)!= '( ')
{
B[j++]=Pop(top);
}
Pop(top);
既用char类型的,又要用float类型的Push(S, x);该怎么编写程序。
还有就是后面的问题应该怎么样去解决。
/*****************************************/
/**** stack.h ****/
/*****************************************/
# include <stdlib.h>
# ifndef NULL
# define NULL ((void*)0);
# endif
typedef char datatype;
typedef struct node{
datatype data;
struct node* next;
} stacknode,* slink;
void Clearstack(slink& top)
{
top=NULL;
}
int Emptystack(slink top)
{
if(top == NULL)
{
return (1);
}
else
{
return (0);
}
}
//..........
datatype Gettop(slink top)
{
return top-> data;
}
//ERROR
void Push(slink& top,datatype x)
{
slink p;
p=(slink)malloc(sizeof(stacknode));
p-> data=x;
p-> next=top;
top=p;
}
datatype Pop(slink& top)
{
datatype x;
slink p;
if(Emptystack(top))
{
return NULL;
}
else
{
x=top-> data;
p=top;
top=top-> next;
free(p);
return (x);
}
}
/*****************************************************/
/**** 表达式求值.cpp ****/
/*****************************************************/
# include "stack.h "
# include <iostream.h>
# include <string.h>
# include <ctype.h>
# include <stdlib.h>
# include <stdio.h>
# define TRUE 1;
# define FALSE 0;
# define OK 1;
# define ERROR 0;
typedef int Status;
//比较调用函数
Status Precede(char x,char y)
//x> =y;则此函数返回TRUE;否则返回FALSE;
{
if(x== '+ '||x== '- '&&y== '* '||y== '/ ')
{
return FALSE;
}
else
{
return TRUE;
}
}
void mid_post(char E[], char B[])
{
int i=0,j=0;
char x;
slink top;
Push(top, '# ');
do
{
x= E[i++];
if(x== '# ')
{
while(!Emptystack(top))
{
B[j++]=Pop(top);
}
}
else
{
if(isdigit(x))
{
B[j++]=x;
}
else
if(x== ') ')
{
while(Gettop(top)!= '( ')
{
B[j++]=Pop(top);
}
Pop(top);