2017-09-27 6 views
1

私は中置式を後置式に変換するcでコーディングしています。私はエラーなくそれを実行しているが、それは私に適切な出力を与えていない。出力がフォームにあると仮定されていますプログラミング中の後置詞変換(A^B^C)/(D * E)

(A^B^C)/(D*E) = ABC^^DE*/しかし、私は私の質問に完全なコードを挿入することはできませんなぜ私は知らない出力がAB^C^DE*/

The convert method is as follows in the comment 

答えて

0

ある これは私がいっぱいですコード

#include <stdio.h> 
#include <conio.h> 
#include <ctype.h> 
#define SIZE 50 
char s[SIZE]; 
int top=-1;  
push(char elem) 
{      
    s[++top]=elem; 
} 

char pop() 
{      
    return(s[top--]); 
} 

int pr(char elem) 
{     
    switch(elem) 
    { 
    case '#': return 0; 
    case '(': return 1; 
    case '+': 
    case '-': return 2; 
    case '*': 
    case '/': return 3; 
    } 
} 

void main() 
{       
    char infx[50],pofx[50],ch,elem; 
    int i=0,k=0; 
    clrscr(); 
    printf("\n\nRead the Infix Expression ? "); 
    scanf("%s",infx); 
    push('#'); 
    while((ch=infx[i++]) != '\0') 
    { 
    if(ch == '(') push(ch); 
    else 
    if(isalnum(ch)) pofx[k++]=ch; 
     else 
    if(ch == ')') 
    { 
     while(s[top] != '(') 
     pofx[k++]=pop(); 
     elem=pop(); 
    } 
    else 
    {  
     while(pr(s[top]) >= pr(ch)) 
     pofx[k++]=pop(); 
     push(ch); 
    } 
    } 
    while(s[top] != '#')  
    pofx[k++]=pop(); 
    pofx[k]='\0';   
    printf("\n\nGiven Infix Expn: %s Postfix Expn: %s\n",infx,pofx); 
    getch(); 
} 
関連する問題