一个关于C语言算法注释

来源:百度知道 编辑:UC知道 时间:2024/06/14 08:23:03
#include <stdio.h>
#include <malloc.h>
#include"stdlib.h"
#define MaxSize 50

void trans(char *exp,char *postexp)
{
struct
{
char data[MaxSize];
int top;
} op;
int i=0;
op.top=-1;
while(*exp!='\0')
{
switch(*exp)
{
case '(':
op.top++;op.data[op.top]=*exp;
exp++;break;
case ')':
while(op.data[op.top]!='(')
{
postexp[i++]=op.data[op.top];
op.top--;
}
op.top--;exp++;break;
case '+':
case '-':
while(op.top!=-1&&op.data[op.top]!='(')
{
postexp[i++]=op.data[op.top];
op.top--;
}
op.top++;op.data[op.top]=*exp;exp++;break;
case '*':
case '/':
while(op.data[op.top]=='*'||op.data[op.top]=='/')
{
postexp[i++]=op.data[op.top];
op.top--;
}

#include <stdio.h>
#include <malloc.h>
#include"stdlib.h"
#define MaxSize 50

void trans(char *exp,char *postexp)
{
struct /* 定义结构体变量op*/
{
char data[MaxSize];
int top;
} op;
int i=0;
op.top=-1;/* 将结构体变量op中整形变量top赋值为-1*/
while(*exp!='\0') /*循环函数读入的指针一直到字符串为0*/
{
switch(*exp) /*选择函数读入的*exp指针*/
{
case '(':
op.top++;op.data[op.top]=*exp; /*若*exp为'(' top身自加一,将op中的date的第op.top项赋值为*exp, */
exp++;break; /*指针exp的地址自加1,然后推出wsitch语句*/
case ')': /* 若exp为')' */
while(op.data[op.top]!='(') /* 开始循环语句 知道结构体变量中date第top项为'('*/
{
postexp[i++]=op.data[op.top]; /*将指针postexp指向的字符串中下一个字符赋值为op结构体中date的第top项*/
op.top--;
}
op.top--;exp++;break;
case '+':

case '-':
while(op.top!=-1&&op.data[op.top]!='(')
{
postexp[i