沈阳航空航天大学课程设计报告
附 录(关键部分程序清单)
#include \#include
#define LEN sizeof(struct Node) #define MAX 1000 #define OK 1 #define ERROR 0 #define OVERFLOW -1 #define TRUE 1 #define FALSE 0 typedef int Status; typedef struct Node { int data; struct Node *prior,*next; }Node,*NodeList;
int axp(int a,int k) //求指数函数值 { int r=1; if(k==0) return 1; for(;k>0;k--) r=r*a; return r; }
Status zhuanhuan(char str[],NodeList &oprh) //输入转换函数 {//将字符串形式的操作数转换成所需的类型 NodeList p; int i,k,buffer; k=buffer=0; oprh=(NodeList)malloc(LEN); oprh->next=oprh; oprh->prior=oprh; for(i=strlen(str)-1;i>=0;i--) { if((i!=0 || (str[0]!='-' && str[0]!='+'))&&(str[i]>'9' || str[i]<'0')) //判断输入是否合法 return ERROR;
15
沈阳航空航天大学课程设计报告
if(str[0]=='0' && str[1]!='\\0') return ERROR; if((str[0]=='-' || str[0]=='+') && str[1]=='0') return ERROR; if(str[i]!='-' && str[i]!='+') { buffer=buffer+(str[i]-'0')*axp(10,k); k++; if(k==4 || str[i-1]=='-' || str[i-1]=='+' || i==0) { p=(NodeList)malloc(LEN);//将新建结点插入到头结点之后 oprh->next->prior=p; p->prior=oprh; p->next=oprh->next; oprh->next=p; p->data=buffer; buffer=k=0; } } } return OK; }
Status shuru(NodeList &opr1,NodeList &opr2,char str[])//输入函数 { int flag=OK;
printf(\请输入第一个操作数:\\n\ scanf(\ getchar(); flag=zhuanhuan(str,opr1); while(!flag) { printf(\整数输入有误,请重新输入:\\n\