#include<stdio.h> //Onur Kılıç #include<conio.h> //108538 #include<string.h> //Computer Eng. char yigin[100]; int top=-1; char cikart(); void ekle(char temp); void infix_to_postfix(char infix[],char postfix[]); int isaret_onceligi(char isaret); int isaret_kontrol(char isaret); char infix[50],postfix[50]; void main(){ int i,isaret,j=0; printf("!!Comp217 Proje odevidir!!\n****************************\n\n"); printf("Ogrenci Bilgileri:\n\nisim:Onur Kilic No:108538 \nDept:Computer Engineering\n****************************\n\n"); printf("infix ifadeyi giriniz:\n"); scanf("%s",&infix); yigin[++top]='#'; for(i=0;i<strlen(infix);i++) { isaret=infix[i]; if(isaret_kontrol(isaret)==0) { postfix[j]=isaret; j++; } else{ if(isaret=='(')ekle(isaret); else if(isaret==')') { while(yigin[top]!='(') { postfix[j]=cikart(); j++; } cikart(); } else{ if(isaret_onceligi(isaret)>isaret_onceligi(yigin[top])) ekle(isaret); else{ while(isaret_onceligi(isaret)<=isaret_onceligi(yigin[top])) { postfix[j]=cikart(); j++; } ekle(isaret); } } } } while(yigin[top]!='#') { postfix[j]=cikart(); j++; } postfix[j]='\0'; printf("Postfix ifade:\n"); puts(postfix); getch(); } int isaret_onceligi(char isaret) { if(isaret=='+'||isaret=='-') return 2; else if(isaret=='*'||isaret=='/') return 4; else if(isaret=='$') return 6; else if(isaret=='('||isaret==')'||isaret=='#') return 1; else return 0; } int isaret_kontrol(char işaret) { if(isaret=='+'||isaret==''||isaret=='*'||isaret=='/'||isaret=='$'||isaret=='('||isaret ==')') return 1; else return 0; } void ekle(char temp) { top++; yigin[top]=temp; } char cikart() { char a; a=yigin[top]; top--; return a; }
© Copyright 2024 Paperzz