SlideShare a Scribd company logo
1 of 3
Download to read offline
Description of program:
You are to write a program name InfixToPostfix.java that converts an infix expression entered
by the user to a postfix expression. The expression may contain the following tokens:
(1) Integer constants (a series of decimal digits).
(2) x (representing a value to be supplied later).
(3) Binary operators (+, -, *, / and %).
(4) Parentheses
Spaces between tokens are allowed but not required. The program will convert the expression to
postfix form and display the converted expression. Upload the file into A7 folder of icollege.
Sample Output:
Enter infix expression: (x + 1) * (x – 2) / 4
Converted expression: x 1 + x 2 - * 4 /
Enter infix expression: 1 2 +
Error in expression!! No operator between operands. Also last token must be an operand.
Enter infix expression: 10.4
Error in expression!! Cannot accept floating point numbers.
Enter infix expression: 1 ( + 2)
Error in expression!! No operator between operand and left parentheses.
Enter infix expression: 5 – (x – 2))
Error in expression!! No matching left parentheses for a right parentheses.
Enter infix expression: 1 ** 2
Error in expression!! The * operator cannot be preceded by a * operator.
Solution
//program for infix to posrtfix convertion
import java.io.*;
class stack
{
char stack1[]=new char[20];
int top;
void push(char ch)
{
top++;
stack1[top]=ch;
}
char pop()
{
char ch;
ch=stack1[top];
top--;
return ch;
}
int pre(char ch)
{
switch(ch)
{
case '-':return 1;
case '+':return 1;
case '*':return 2;
case '/':return 2;
}
retrun 0;
}
boolean operator(char ch)
{
if(ch=='/'||ch=='*'||ch=='+'||ch=='-')
return true;
else
return false;
}
boolean isAlpha(char ch)
{
if(ch>='a'&&ch<='z'||ch>='0'&&ch=='9')
return true;
else
return false;
}
void postfix(String str)
{
char output[]=new char[str.length()];
char ch;
int p=0,i;
for(i=0;ipre(stack1[top])) || stack1[top]=='(')
{
push(ch);
}
}
else if(pre(ch)<=pre(stack1[top]))
{
output[p++]=pop();
push(ch);
}
else if(ch=='(')
{
while((ch=po())!='(')
{
output[p++]=ch;
}
}
}
while(top!=0)
{
output[p++]=pop();
}
for(int j=0;j

More Related Content

Similar to Description of programYou are to write a program name InfixToPost.pdf

C standard library functions
C standard library functionsC standard library functions
C standard library functionsVaishnavee Sharma
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxLikhil181
 
CJPCCS BCA VISNAGAR functions in C language
CJPCCS BCA VISNAGAR  functions in C languageCJPCCS BCA VISNAGAR  functions in C language
CJPCCS BCA VISNAGAR functions in C languageFCSCJCS
 
Operator Overloading and Scope of Variable
Operator Overloading and Scope of VariableOperator Overloading and Scope of Variable
Operator Overloading and Scope of VariableMOHIT DADU
 
Generacion de codigo ensamblado
Generacion de codigo ensambladoGeneracion de codigo ensamblado
Generacion de codigo ensambladotre_na_gil
 
EMC Documentum xCP 2.x Tips for application migration v1.1
EMC Documentum xCP 2.x Tips for application migration v1.1EMC Documentum xCP 2.x Tips for application migration v1.1
EMC Documentum xCP 2.x Tips for application migration v1.1Haytham Ghandour
 
Educational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdfEducational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdfrajeshjangid1865
 
Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make YASHU40
 
Functions in python
Functions in pythonFunctions in python
Functions in pythoncolorsof
 
It’s sometimes useful to make a little language for a simple problem.pdf
It’s sometimes useful to make a little language for a simple problem.pdfIt’s sometimes useful to make a little language for a simple problem.pdf
It’s sometimes useful to make a little language for a simple problem.pdfarri2009av
 
Functions_21_22.pdf
Functions_21_22.pdfFunctions_21_22.pdf
Functions_21_22.pdfpaijitk
 

Similar to Description of programYou are to write a program name InfixToPost.pdf (20)

Function BPK2
Function BPK2Function BPK2
Function BPK2
 
C functions list
C functions listC functions list
C functions list
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
Functions
Functions Functions
Functions
 
Python_UNIT-I.pptx
Python_UNIT-I.pptxPython_UNIT-I.pptx
Python_UNIT-I.pptx
 
CJPCCS BCA VISNAGAR functions in C language
CJPCCS BCA VISNAGAR  functions in C languageCJPCCS BCA VISNAGAR  functions in C language
CJPCCS BCA VISNAGAR functions in C language
 
Operator Overloading and Scope of Variable
Operator Overloading and Scope of VariableOperator Overloading and Scope of Variable
Operator Overloading and Scope of Variable
 
Generacion de codigo ensamblado
Generacion de codigo ensambladoGeneracion de codigo ensamblado
Generacion de codigo ensamblado
 
EMC Documentum xCP 2.x Tips for application migration v1.1
EMC Documentum xCP 2.x Tips for application migration v1.1EMC Documentum xCP 2.x Tips for application migration v1.1
EMC Documentum xCP 2.x Tips for application migration v1.1
 
Educational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdfEducational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdf
 
C function
C functionC function
C function
 
Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make
 
module 4.pptx
module 4.pptxmodule 4.pptx
module 4.pptx
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
It’s sometimes useful to make a little language for a simple problem.pdf
It’s sometimes useful to make a little language for a simple problem.pdfIt’s sometimes useful to make a little language for a simple problem.pdf
It’s sometimes useful to make a little language for a simple problem.pdf
 
Functions_21_22.pdf
Functions_21_22.pdfFunctions_21_22.pdf
Functions_21_22.pdf
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 

More from arihantelehyb

for the normal distrbution, the proportion in the tail beyond z= 1.5.pdf
for the normal distrbution, the proportion in the tail beyond z= 1.5.pdffor the normal distrbution, the proportion in the tail beyond z= 1.5.pdf
for the normal distrbution, the proportion in the tail beyond z= 1.5.pdfarihantelehyb
 
For a square matrix A, which vectors are orthogonal to the vectors i.pdf
For a square matrix A, which vectors are orthogonal to the vectors i.pdfFor a square matrix A, which vectors are orthogonal to the vectors i.pdf
For a square matrix A, which vectors are orthogonal to the vectors i.pdfarihantelehyb
 
Five individuals, including A and B, take seats around a circular ta.pdf
Five individuals, including A and B, take seats around a circular ta.pdfFive individuals, including A and B, take seats around a circular ta.pdf
Five individuals, including A and B, take seats around a circular ta.pdfarihantelehyb
 
Explain the experiments of Griffiths (1928) and Hershey Chase (1952).pdf
Explain the experiments of Griffiths (1928) and Hershey Chase (1952).pdfExplain the experiments of Griffiths (1928) and Hershey Chase (1952).pdf
Explain the experiments of Griffiths (1928) and Hershey Chase (1952).pdfarihantelehyb
 
Energy doing work Fuel of the cell Working part of an enzyme (2 w.pdf
Energy doing work  Fuel of the cell  Working part of an enzyme (2 w.pdfEnergy doing work  Fuel of the cell  Working part of an enzyme (2 w.pdf
Energy doing work Fuel of the cell Working part of an enzyme (2 w.pdfarihantelehyb
 
• Define transcription• Define translation• What are the 3 steps.pdf
• Define transcription• Define translation• What are the 3 steps.pdf• Define transcription• Define translation• What are the 3 steps.pdf
• Define transcription• Define translation• What are the 3 steps.pdfarihantelehyb
 
Which of the following represents the internal environment of the bod.pdf
Which of the following represents the internal environment of the bod.pdfWhich of the following represents the internal environment of the bod.pdf
Which of the following represents the internal environment of the bod.pdfarihantelehyb
 
why does venus experience so little temperature changes compared to .pdf
why does venus experience so little temperature changes compared to .pdfwhy does venus experience so little temperature changes compared to .pdf
why does venus experience so little temperature changes compared to .pdfarihantelehyb
 
Who is considered the author of The Way of Life, which is Daoisms .pdf
Who is considered the author of The Way of Life, which is Daoisms .pdfWho is considered the author of The Way of Life, which is Daoisms .pdf
Who is considered the author of The Way of Life, which is Daoisms .pdfarihantelehyb
 
Which of the following is not a function of proteinsa.         .pdf
Which of the following is not a function of proteinsa.         .pdfWhich of the following is not a function of proteinsa.         .pdf
Which of the following is not a function of proteinsa.         .pdfarihantelehyb
 
what is the marketSolutionAccording to Britannica Market, a .pdf
what is the marketSolutionAccording to Britannica Market, a .pdfwhat is the marketSolutionAccording to Britannica Market, a .pdf
what is the marketSolutionAccording to Britannica Market, a .pdfarihantelehyb
 
What happens when two shock waves collide What happens specifically.pdf
What happens when two shock waves collide What happens specifically.pdfWhat happens when two shock waves collide What happens specifically.pdf
What happens when two shock waves collide What happens specifically.pdfarihantelehyb
 
What is input A. Any data or information that is processed and pres.pdf
What is input  A. Any data or information that is processed and pres.pdfWhat is input  A. Any data or information that is processed and pres.pdf
What is input A. Any data or information that is processed and pres.pdfarihantelehyb
 
What are the main components of the chemiosmotic mechanism in mitoch.pdf
What are the main components of the chemiosmotic mechanism in mitoch.pdfWhat are the main components of the chemiosmotic mechanism in mitoch.pdf
What are the main components of the chemiosmotic mechanism in mitoch.pdfarihantelehyb
 
Customers arrive at bakery at an average of 10 customers per hour. W.pdf
Customers arrive at bakery at an average of 10 customers per hour. W.pdfCustomers arrive at bakery at an average of 10 customers per hour. W.pdf
Customers arrive at bakery at an average of 10 customers per hour. W.pdfarihantelehyb
 
Two different strains of a mutant phage infect a single bacterium. O.pdf
Two different strains of a mutant phage infect a single bacterium. O.pdfTwo different strains of a mutant phage infect a single bacterium. O.pdf
Two different strains of a mutant phage infect a single bacterium. O.pdfarihantelehyb
 
Consider this you have two cell lines, a macrophage cell line and a.pdf
Consider this you have two cell lines, a macrophage cell line and a.pdfConsider this you have two cell lines, a macrophage cell line and a.pdf
Consider this you have two cell lines, a macrophage cell line and a.pdfarihantelehyb
 
RNA splicing activities can be regulated in cells by various activat.pdf
RNA splicing activities can be regulated in cells by various activat.pdfRNA splicing activities can be regulated in cells by various activat.pdf
RNA splicing activities can be regulated in cells by various activat.pdfarihantelehyb
 
Required Summarize why revenue is such a critical account in most c.pdf
Required Summarize why revenue is such a critical account in most c.pdfRequired Summarize why revenue is such a critical account in most c.pdf
Required Summarize why revenue is such a critical account in most c.pdfarihantelehyb
 
quizlet com ezto.mheducation.com nline Store Apple Apple Disney Disne.pdf
quizlet com ezto.mheducation.com nline Store Apple Apple Disney Disne.pdfquizlet com ezto.mheducation.com nline Store Apple Apple Disney Disne.pdf
quizlet com ezto.mheducation.com nline Store Apple Apple Disney Disne.pdfarihantelehyb
 

More from arihantelehyb (20)

for the normal distrbution, the proportion in the tail beyond z= 1.5.pdf
for the normal distrbution, the proportion in the tail beyond z= 1.5.pdffor the normal distrbution, the proportion in the tail beyond z= 1.5.pdf
for the normal distrbution, the proportion in the tail beyond z= 1.5.pdf
 
For a square matrix A, which vectors are orthogonal to the vectors i.pdf
For a square matrix A, which vectors are orthogonal to the vectors i.pdfFor a square matrix A, which vectors are orthogonal to the vectors i.pdf
For a square matrix A, which vectors are orthogonal to the vectors i.pdf
 
Five individuals, including A and B, take seats around a circular ta.pdf
Five individuals, including A and B, take seats around a circular ta.pdfFive individuals, including A and B, take seats around a circular ta.pdf
Five individuals, including A and B, take seats around a circular ta.pdf
 
Explain the experiments of Griffiths (1928) and Hershey Chase (1952).pdf
Explain the experiments of Griffiths (1928) and Hershey Chase (1952).pdfExplain the experiments of Griffiths (1928) and Hershey Chase (1952).pdf
Explain the experiments of Griffiths (1928) and Hershey Chase (1952).pdf
 
Energy doing work Fuel of the cell Working part of an enzyme (2 w.pdf
Energy doing work  Fuel of the cell  Working part of an enzyme (2 w.pdfEnergy doing work  Fuel of the cell  Working part of an enzyme (2 w.pdf
Energy doing work Fuel of the cell Working part of an enzyme (2 w.pdf
 
• Define transcription• Define translation• What are the 3 steps.pdf
• Define transcription• Define translation• What are the 3 steps.pdf• Define transcription• Define translation• What are the 3 steps.pdf
• Define transcription• Define translation• What are the 3 steps.pdf
 
Which of the following represents the internal environment of the bod.pdf
Which of the following represents the internal environment of the bod.pdfWhich of the following represents the internal environment of the bod.pdf
Which of the following represents the internal environment of the bod.pdf
 
why does venus experience so little temperature changes compared to .pdf
why does venus experience so little temperature changes compared to .pdfwhy does venus experience so little temperature changes compared to .pdf
why does venus experience so little temperature changes compared to .pdf
 
Who is considered the author of The Way of Life, which is Daoisms .pdf
Who is considered the author of The Way of Life, which is Daoisms .pdfWho is considered the author of The Way of Life, which is Daoisms .pdf
Who is considered the author of The Way of Life, which is Daoisms .pdf
 
Which of the following is not a function of proteinsa.         .pdf
Which of the following is not a function of proteinsa.         .pdfWhich of the following is not a function of proteinsa.         .pdf
Which of the following is not a function of proteinsa.         .pdf
 
what is the marketSolutionAccording to Britannica Market, a .pdf
what is the marketSolutionAccording to Britannica Market, a .pdfwhat is the marketSolutionAccording to Britannica Market, a .pdf
what is the marketSolutionAccording to Britannica Market, a .pdf
 
What happens when two shock waves collide What happens specifically.pdf
What happens when two shock waves collide What happens specifically.pdfWhat happens when two shock waves collide What happens specifically.pdf
What happens when two shock waves collide What happens specifically.pdf
 
What is input A. Any data or information that is processed and pres.pdf
What is input  A. Any data or information that is processed and pres.pdfWhat is input  A. Any data or information that is processed and pres.pdf
What is input A. Any data or information that is processed and pres.pdf
 
What are the main components of the chemiosmotic mechanism in mitoch.pdf
What are the main components of the chemiosmotic mechanism in mitoch.pdfWhat are the main components of the chemiosmotic mechanism in mitoch.pdf
What are the main components of the chemiosmotic mechanism in mitoch.pdf
 
Customers arrive at bakery at an average of 10 customers per hour. W.pdf
Customers arrive at bakery at an average of 10 customers per hour. W.pdfCustomers arrive at bakery at an average of 10 customers per hour. W.pdf
Customers arrive at bakery at an average of 10 customers per hour. W.pdf
 
Two different strains of a mutant phage infect a single bacterium. O.pdf
Two different strains of a mutant phage infect a single bacterium. O.pdfTwo different strains of a mutant phage infect a single bacterium. O.pdf
Two different strains of a mutant phage infect a single bacterium. O.pdf
 
Consider this you have two cell lines, a macrophage cell line and a.pdf
Consider this you have two cell lines, a macrophage cell line and a.pdfConsider this you have two cell lines, a macrophage cell line and a.pdf
Consider this you have two cell lines, a macrophage cell line and a.pdf
 
RNA splicing activities can be regulated in cells by various activat.pdf
RNA splicing activities can be regulated in cells by various activat.pdfRNA splicing activities can be regulated in cells by various activat.pdf
RNA splicing activities can be regulated in cells by various activat.pdf
 
Required Summarize why revenue is such a critical account in most c.pdf
Required Summarize why revenue is such a critical account in most c.pdfRequired Summarize why revenue is such a critical account in most c.pdf
Required Summarize why revenue is such a critical account in most c.pdf
 
quizlet com ezto.mheducation.com nline Store Apple Apple Disney Disne.pdf
quizlet com ezto.mheducation.com nline Store Apple Apple Disney Disne.pdfquizlet com ezto.mheducation.com nline Store Apple Apple Disney Disne.pdf
quizlet com ezto.mheducation.com nline Store Apple Apple Disney Disne.pdf
 

Recently uploaded

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
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
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
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
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
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
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
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
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
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
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.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...
 

Description of programYou are to write a program name InfixToPost.pdf

  • 1. Description of program: You are to write a program name InfixToPostfix.java that converts an infix expression entered by the user to a postfix expression. The expression may contain the following tokens: (1) Integer constants (a series of decimal digits). (2) x (representing a value to be supplied later). (3) Binary operators (+, -, *, / and %). (4) Parentheses Spaces between tokens are allowed but not required. The program will convert the expression to postfix form and display the converted expression. Upload the file into A7 folder of icollege. Sample Output: Enter infix expression: (x + 1) * (x – 2) / 4 Converted expression: x 1 + x 2 - * 4 / Enter infix expression: 1 2 + Error in expression!! No operator between operands. Also last token must be an operand. Enter infix expression: 10.4 Error in expression!! Cannot accept floating point numbers. Enter infix expression: 1 ( + 2) Error in expression!! No operator between operand and left parentheses. Enter infix expression: 5 – (x – 2)) Error in expression!! No matching left parentheses for a right parentheses. Enter infix expression: 1 ** 2 Error in expression!! The * operator cannot be preceded by a * operator. Solution //program for infix to posrtfix convertion import java.io.*; class stack { char stack1[]=new char[20]; int top;
  • 2. void push(char ch) { top++; stack1[top]=ch; } char pop() { char ch; ch=stack1[top]; top--; return ch; } int pre(char ch) { switch(ch) { case '-':return 1; case '+':return 1; case '*':return 2; case '/':return 2; } retrun 0; } boolean operator(char ch) { if(ch=='/'||ch=='*'||ch=='+'||ch=='-') return true; else return false; } boolean isAlpha(char ch) { if(ch>='a'&&ch<='z'||ch>='0'&&ch=='9') return true; else return false;
  • 3. } void postfix(String str) { char output[]=new char[str.length()]; char ch; int p=0,i; for(i=0;ipre(stack1[top])) || stack1[top]=='(') { push(ch); } } else if(pre(ch)<=pre(stack1[top])) { output[p++]=pop(); push(ch); } else if(ch=='(') { while((ch=po())!='(') { output[p++]=ch; } } } while(top!=0) { output[p++]=pop(); } for(int j=0;j