SlideShare una empresa de Scribd logo
1 de 9
/* Write a C program that uses Stack operations to perform the following:

            i) Converting infix expression into postfix expression

            ii) Evaluating the postfix expression */



#include<stdio.h>

#include<conio.h>



int st[100];

int st_top=-1;



int cal(char post[]);

void in_post(char in[]);

void push_item(int it);

int pop_item();

int st_ISP(char t);

int st_ICP(char t);



/*main function*/

void main()

{

    char in[100],post[100];

    clrscr();

    printf("ntEnter the Infix Expression: ");

    gets(in);
in_post(in);

    getch();

}

/*end main*/



void push_item(int it)

{

    if(st_top==99)

    {

        printf("nnt*STACK is Full*");

        getch();

        exit(1);

    }

    st[++st_top]=it;

}



int pop_item()

{

    int it;

    if(st_top==-1)

    {

        getch();

    }

    return(st[st_top--]);
}



/*Function for converting an infix expression to a postfix expression. */

void in_post(char in[])

{

    int x=0,y=0,z,result=0;

    char a,c, post[100];

    char t;

    push_item('0');

    t=in[x];

    while(t!='0')

    {

        if(isalnum(t))

        /*For checking whether the value in t is an alphabet or number. */

        {

            post[y]=t;

            y++;

        }

        else if(t=='(')

        {

            push_item('(');

        }

        else if(t==')')

        {
while(st[st_top]!='(')

        {

             c=pop_item();

             post[y]=c;

             y++;

        }

    c=pop_item();

    }

    else

    {

        while(st_ISP(st[st_top])>=st_ICP(t))

        {

             c=pop_item();

             post[y]=c;

             y++;

        }

        push_item(t);

    }

    x++;

    t=in[x];

}



while(st_top!=-1)

{
c=pop_item();

        post[y]=c;

        y++;

    }

    printf("ntThe Postfix Expression is:");



    for(z=0;z<y;z++)

        printf("%c",post[z]);

    printf("nnDo you want to evaluate the Result of Postfix Expression?(Y/N):");

    scanf("%c",&a);

    if(a=='y' || a=='Y')

    {

        result=cal(post);

        printf("nntResult is: %dn",result);

        getch();

    }

    else if(a=='n' || a=='N')

    {

        exit(0);

    }

}



/*Determining priority of inside elements*/

int st_ISP(char t)
{

    switch(t)

    {

        case '(':return (10);

        case ')':return (9);

        case '+':return (7);

        case '-':return (7);

        case '*':return (8);

        case '/':return (8);

        case '0':return (0);

        default: printf("Expression is invalid.");

        break;

    }

    return 0;

}



/*Determining priority of approaching elements*/

int st_ICP(char t)

{

    switch(t)

    {



        case '(':return (10);

        case ')':return (9);
case '+':return (7);

        case '-':return (7);

        case '*':return (8);

        case '/':return (8);

        case '0':return (0);

        default: printf("Expression is invalid.");

        break;

    }

    return 0;

}



/*Evaluating the result of postfix expression*/

int cal(char post[])

{

    int m,n,x,y,j=0,len;

    len=strlen(post);

    while(j<len)

    {

        if(isdigit(post[j]))

        {

            x=post[j]-'0';

            push_item(x);

        }

        else
{

        m=pop_item();

        n=pop_item();



        switch(post[j])

        {

             case '+':x=n+m;

             break;

             case '-':x=n-m;

             break;

             case '*':x=n*m;

             break;

             case '/':x=n/m;

             break;

        }

        push_item(x);

    }

    j++;

}

if(st_top>0)

{

    printf("Number of Operands are more than Operators.");

    exit(0);

}
else

    {

        y=pop_item();

        return (y);

    }

    return 0;

}

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Add digits of number in c
Add digits of number in c Add digits of number in c
Add digits of number in c
 
Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Palindrome number program c
Palindrome number program cPalindrome number program c
Palindrome number program c
 
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4
 
Function basics
Function basicsFunction basics
Function basics
 
Computer programing w
Computer programing wComputer programing w
Computer programing w
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
week-21x
week-21xweek-21x
week-21x
 
week-15x
week-15xweek-15x
week-15x
 

Destacado (6)

ch6
ch6ch6
ch6
 
BrainFingerprintingpresentation
BrainFingerprintingpresentationBrainFingerprintingpresentation
BrainFingerprintingpresentation
 
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENTDISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
 
PPT (2)
PPT (2)PPT (2)
PPT (2)
 
ch14
ch14ch14
ch14
 
week-23x
week-23xweek-23x
week-23x
 

Similar a week-18x

Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docxkatherncarlyle
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
data structure and algorithm.pdf
data structure and algorithm.pdfdata structure and algorithm.pdf
data structure and algorithm.pdfAsrinath1
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and CEleanor McHugh
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 

Similar a week-18x (20)

VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
week-16x
week-16xweek-16x
week-16x
 
#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
data structure and algorithm.pdf
data structure and algorithm.pdfdata structure and algorithm.pdf
data structure and algorithm.pdf
 
Stack prgs
Stack prgsStack prgs
Stack prgs
 
Struct examples
Struct examplesStruct examples
Struct examples
 
Lab Question
Lab QuestionLab Question
Lab Question
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
C programs
C programsC programs
C programs
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 

Más de KITE www.kitecolleges.com (18)

ch16
ch16ch16
ch16
 
holographic versatile disc
holographic versatile discholographic versatile disc
holographic versatile disc
 
week-22x
week-22xweek-22x
week-22x
 
week-5x
week-5xweek-5x
week-5x
 
week-3x
week-3xweek-3x
week-3x
 
ch8
ch8ch8
ch8
 
Intro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.ukIntro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.uk
 
ch17
ch17ch17
ch17
 
ch4
ch4ch4
ch4
 
week-7x
week-7xweek-7x
week-7x
 
week-9x
week-9xweek-9x
week-9x
 
week-14x
week-14xweek-14x
week-14x
 
AIRBORNE
AIRBORNEAIRBORNE
AIRBORNE
 
ch2
ch2ch2
ch2
 
week-2x
week-2xweek-2x
week-2x
 
ch3
ch3ch3
ch3
 
Entity Classes and Attributes
Entity Classes and AttributesEntity Classes and Attributes
Entity Classes and Attributes
 
week-20x
week-20xweek-20x
week-20x
 

Último

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Último (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

week-18x

  • 1. /* Write a C program that uses Stack operations to perform the following: i) Converting infix expression into postfix expression ii) Evaluating the postfix expression */ #include<stdio.h> #include<conio.h> int st[100]; int st_top=-1; int cal(char post[]); void in_post(char in[]); void push_item(int it); int pop_item(); int st_ISP(char t); int st_ICP(char t); /*main function*/ void main() { char in[100],post[100]; clrscr(); printf("ntEnter the Infix Expression: "); gets(in);
  • 2. in_post(in); getch(); } /*end main*/ void push_item(int it) { if(st_top==99) { printf("nnt*STACK is Full*"); getch(); exit(1); } st[++st_top]=it; } int pop_item() { int it; if(st_top==-1) { getch(); } return(st[st_top--]);
  • 3. } /*Function for converting an infix expression to a postfix expression. */ void in_post(char in[]) { int x=0,y=0,z,result=0; char a,c, post[100]; char t; push_item('0'); t=in[x]; while(t!='0') { if(isalnum(t)) /*For checking whether the value in t is an alphabet or number. */ { post[y]=t; y++; } else if(t=='(') { push_item('('); } else if(t==')') {
  • 4. while(st[st_top]!='(') { c=pop_item(); post[y]=c; y++; } c=pop_item(); } else { while(st_ISP(st[st_top])>=st_ICP(t)) { c=pop_item(); post[y]=c; y++; } push_item(t); } x++; t=in[x]; } while(st_top!=-1) {
  • 5. c=pop_item(); post[y]=c; y++; } printf("ntThe Postfix Expression is:"); for(z=0;z<y;z++) printf("%c",post[z]); printf("nnDo you want to evaluate the Result of Postfix Expression?(Y/N):"); scanf("%c",&a); if(a=='y' || a=='Y') { result=cal(post); printf("nntResult is: %dn",result); getch(); } else if(a=='n' || a=='N') { exit(0); } } /*Determining priority of inside elements*/ int st_ISP(char t)
  • 6. { switch(t) { case '(':return (10); case ')':return (9); case '+':return (7); case '-':return (7); case '*':return (8); case '/':return (8); case '0':return (0); default: printf("Expression is invalid."); break; } return 0; } /*Determining priority of approaching elements*/ int st_ICP(char t) { switch(t) { case '(':return (10); case ')':return (9);
  • 7. case '+':return (7); case '-':return (7); case '*':return (8); case '/':return (8); case '0':return (0); default: printf("Expression is invalid."); break; } return 0; } /*Evaluating the result of postfix expression*/ int cal(char post[]) { int m,n,x,y,j=0,len; len=strlen(post); while(j<len) { if(isdigit(post[j])) { x=post[j]-'0'; push_item(x); } else
  • 8. { m=pop_item(); n=pop_item(); switch(post[j]) { case '+':x=n+m; break; case '-':x=n-m; break; case '*':x=n*m; break; case '/':x=n/m; break; } push_item(x); } j++; } if(st_top>0) { printf("Number of Operands are more than Operators."); exit(0); }
  • 9. else { y=pop_item(); return (y); } return 0; }