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 (20)

Function basics
Function basicsFunction basics
Function basics
 
week-1x
week-1xweek-1x
week-1x
 
week-16x
week-16xweek-16x
week-16x
 
week-6x
week-6xweek-6x
week-6x
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
week-4x
week-4xweek-4x
week-4x
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
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
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
 
Circular queue
Circular queueCircular queue
Circular queue
 
Implementing stack
Implementing stackImplementing stack
Implementing stack
 
Intro to c programming
Intro to c programmingIntro to c programming
Intro to c programming
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphism
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
 

Destacado

Destacado (14)

Deber henrry
Deber henrryDeber henrry
Deber henrry
 
Natalie Barnhart pd. 5
Natalie Barnhart pd. 5Natalie Barnhart pd. 5
Natalie Barnhart pd. 5
 
ePagine boekenbeurs presentatie 02/11/2009
ePagine boekenbeurs presentatie 02/11/2009ePagine boekenbeurs presentatie 02/11/2009
ePagine boekenbeurs presentatie 02/11/2009
 
Facebook
FacebookFacebook
Facebook
 
Eduvision - Proefles Cursus Joomla
Eduvision - Proefles Cursus JoomlaEduvision - Proefles Cursus Joomla
Eduvision - Proefles Cursus Joomla
 
Performing Tolerance Stack Ups Using Automated Excel Calculator By Arash Vakily
Performing Tolerance Stack Ups Using Automated Excel Calculator By Arash VakilyPerforming Tolerance Stack Ups Using Automated Excel Calculator By Arash Vakily
Performing Tolerance Stack Ups Using Automated Excel Calculator By Arash Vakily
 
BrainFingerprintingpresentation
BrainFingerprintingpresentationBrainFingerprintingpresentation
BrainFingerprintingpresentation
 
Compiler design lab programs
Compiler design lab programs Compiler design lab programs
Compiler design lab programs
 
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENTDISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
 
ch6
ch6ch6
ch6
 
PPT (2)
PPT (2)PPT (2)
PPT (2)
 
It4466 finale 2_kz2
It4466 finale 2_kz2It4466 finale 2_kz2
It4466 finale 2_kz2
 
An Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 CanvasAn Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 Canvas
 
Seq 3 v3 management motivation equipe deuxieme partie 75 diapos-marcel nizon
Seq 3 v3  management motivation equipe deuxieme partie 75 diapos-marcel nizonSeq 3 v3  management motivation equipe deuxieme partie 75 diapos-marcel nizon
Seq 3 v3 management motivation equipe deuxieme partie 75 diapos-marcel nizon
 

Similar a week-17x

#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
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresLakshmi Sarvani Videla
 

Similar a week-17x (20)

VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
week-15x
week-15xweek-15x
week-15x
 
#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
 
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++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 

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

ch14
ch14ch14
ch14
 
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-23x
week-23xweek-23x
week-23x
 
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
 

Último

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 

Último (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

week-17x

  • 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; }