SHARE
TWEET

INFIX

a guest Mar 21st, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma hdrstop
  2. #pragma argsused
  3.  
  4. #ifdef _WIN32
  5. #include <tchar.h>
  6. #else
  7.   typedef char _TCHAR;
  8.   #define _tmain main
  9. #endif
  10.  
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <stdlib>
  14.  
  15. struct tNode{
  16.     double oprnd;
  17.     char oprnt;
  18.     tNode *Next;
  19. } *HeadInfix, *TailInfix, *HeadPostfix, *TailPostfix, *Infix, *Postfix, *Hapus, *Baru, *Top;
  20.  
  21. bool is_operator(char x){
  22.     bool y;
  23.     if (x=='-' || x=='+' || x=='*' || x=='/' || x=='^' || x=='(' || x==')' ){
  24.         y=true;
  25.     } else{
  26.         y=false;
  27.     }
  28.     return y;
  29. }
  30.  
  31.  void _tmain(int argc, _TCHAR* argv[])
  32. {
  33.     char notasi[]="52.3+9*(40-38)^3/2", oprt, tmps[20];
  34.     double oprndi, oprnd1, oprnd2, hasil;
  35.     int i,j;
  36.  
  37.     HeadInfix=TailInfix=HeadPostfix=TailPostfix=Top=NULL;
  38.     for (i =0; i<strlen(notasi); i++){
  39.         if( (notasi[i]>='0' && notasi[i]<='9') || notasi[i]=='.'){ //jika merupakan angka =
  40.             //printf("%c", notasi[i]);
  41.             tmps[j]=notasi[i];
  42.             j++;
  43.         }else if(is_operator(notasi[i]) ) {//jika operator
  44.         tmps[j]=NULL;
  45.         hasil=atof(tmps);
  46.         j=0;
  47.         printf("%5.2f\n", hasil); //cetak operand
  48.         //printf("\n%c\n", notasi[i]);
  49.         }
  50.         printf("%c\n", notasi[i]); //cetak operator
  51.     }
  52. }
  53.  
  54. if (j>0) {
  55.     tmps[j]=NULL;
  56.     hasil=atof(tmps);
  57.     j=0;
  58.     printf("%5.2f\n", hasil); //cetak operand
  59. }
  60.     getch();
  61.  
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top