Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma hdrstop
- #pragma argsused
- #ifdef _WIN32
- #include <tchar.h>
- #else
- typedef char _TCHAR;
- #define _tmain main
- #endif
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib>
- struct tNode{
- double oprnd;
- char oprnt;
- tNode *Next;
- } *HeadInfix, *TailInfix, *HeadPostfix, *TailPostfix, *Infix, *Postfix, *Hapus, *Baru, *Top;
- bool is_operator(char x){
- bool y;
- if (x=='-' || x=='+' || x=='*' || x=='/' || x=='^' || x=='(' || x==')' ){
- y=true;
- } else{
- y=false;
- }
- return y;
- }
- void _tmain(int argc, _TCHAR* argv[])
- {
- char notasi[]="52.3+9*(40-38)^3/2", oprt, tmps[20];
- double oprndi, oprnd1, oprnd2, hasil;
- int i,j;
- HeadInfix=TailInfix=HeadPostfix=TailPostfix=Top=NULL;
- for (i =0; i<strlen(notasi); i++){
- if( (notasi[i]>='0' && notasi[i]<='9') || notasi[i]=='.'){ //jika merupakan angka =
- //printf("%c", notasi[i]);
- tmps[j]=notasi[i];
- j++;
- }else if(is_operator(notasi[i]) ) {//jika operator
- tmps[j]=NULL;
- hasil=atof(tmps);
- j=0;
- printf("%5.2f\n", hasil); //cetak operand
- //printf("\n%c\n", notasi[i]);
- }
- printf("%c\n", notasi[i]); //cetak operator
- }
- }
- if (j>0) {
- tmps[j]=NULL;
- hasil=atof(tmps);
- j=0;
- printf("%5.2f\n", hasil); //cetak operand
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement