1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
labwork [276]
3 years ago
9

Convert infix to postfix

Computers and Technology
1 answer:
kvv77 [185]3 years ago
4 0

Answer:

static int checkSymbol(char ch)

{

switch (ch)

{

case '+':

case '-':

return 1;

case '*':

case '/':

return 2;

case '^':

return 3;

}

return -1;

}

static String convertInfixToPostfix(String expression)

{

String calculation = new String("");

Stack<Character> operands = new Stack<>();

Stack<Character> operators = new Stack<>();

 

for (int i = 0; i<expression.length(); ++i)

{

char c = expression.charAt(i);

if (Character.isLetterOrDigit(c))

operands.push(c);

else if (c == '(')

operators.push(c);

 

else if (c == ')')

{

while (!operators.isEmpty() && operators.peek() != '(')

operands.push(operators.pop());

 

if (!operators.isEmpty() && operators.peek() != '(')

return NULL;    

else

operators.pop();

}

else

{

while (!operators.isEmpty() && checkSymbol(c) <= checkSymbol(operators.peek()))

operands.push(operators.pop());

operators.push(c);

}

}

while (!operators.isEmpty())

operands.push(operators.pop());

while (!operands.isEmpty())

calculation+=operands.pop();

calculation=calculation.reverse();

return calculation;

}

Explanation:

  • Create the checkSymbol function to see what symbol is being passed to the stack.
  • Create the convertInfixToPostfix function that keeps track of the operands and the operators stack.
  • Use conditional statements to check whether the character being passed is a letter, digit, symbol or a bracket.
  • While the operators is  not empty, keep pushing the character to the operators stack.
  • At last reverse and return the calculation which has all the results.
You might be interested in
The fraction 460/7 is closest to which of the following whole numbers?
Bess [88]
I don’t see any of “the following numbers”
3 0
3 years ago
A section at the top of the page that makes it easy for the recipient to respond to a letter is called a(n
Umnica [9.8K]

Answer:

Address block.

Explanation:

7 0
3 years ago
Which component of service-oriented DSS can be defined as data that describes the meaning and structure of business data, as wel
Licemer1 [7]

Answer:

The correct answer to the following question will be Metadata Management.

Explanation:

The management of data about the other data is known as Metadata Management. When the data is generated, updated, deleted, created, metadata is generated.

Benefits of Metadata management:

  • To locate data for a person, the metadata management make it easier.
  • Project delivery become faster.
  • Maintain information of organization.

Hence, the Metadata Management will be the best suitable component which defined as the structure and meaning of business data.

4 0
3 years ago
Plese give three examples of specilized servers.
MariettaO [177]
1.Extended border node (EBN)
2.Central directory server (CDS)
3.Branch extender (BEX or BrEx or BrNN)
5 0
3 years ago
Read 2 more answers
How are devices connected to each other via Bluetooth? Choose two answers.
Olegator [25]

Answer:

Pairing and Passkey or PIN

Explanation:

8 0
3 years ago
Other questions:
  • How many megabytes of data can a factory made audio cd hold?
    13·1 answer
  • To change the overall design of an entire document to include colors, fonts, and effects, a user should apply a?
    8·2 answers
  • Which resource helps a user access a cloud service?
    8·1 answer
  • The order of precedence is very important when building formulas in Excel. Which of the following formulas will produce 778 as t
    11·1 answer
  • What icon is usually used to indicate an attachment feature?
    14·2 answers
  • Definition of powerpoint animation
    14·1 answer
  • What feature sets Macs apart from other operating systems?
    5·1 answer
  • 13) An-Excel-file-is-generally called-a-l-an:
    6·1 answer
  • If, after fetching a value from memory, we discover that the system has returned only half of the bits that we expected; it is l
    8·1 answer
  • In a finite state machine, state transitions happen only: a. When the reset causes a clock pulse on the D outputs of the flip-fl
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!