Write the function pop in c, Basic Computer Science

Assignment Help:

QUESTION

(a) Convert each of the following expressions to prefix and postfix.

(i) (A+B)*(C+D)

(ii) A-B/(C*D^E) (^ denotes exponentiation)

(b) The following algorithm converts an infix expression into its postfix representation. We have assumed that the infix expressions contain only the operators +, -, * and /. The expressions do not contain parentheses. Examples of valid expressions are A+B*C and A/B+C/D-E.

opstk = the empty stack;

while (not end of input) {

symb = next input character;

if (symb is an operand)

add symb to the postfix string

else{

while(!empty(opstk) && prcd(stacktop(opstk),symb)){

topsymb = pop(opstk);

add topsymb to the postfix string;

}

push(opstk,symb);

}

}

while(!empty(opstk)){

topsymb = pop(opstk);

add topsymb to the postfix string;

}

(i) Write the function empty in C. The function empty must return TRUE if the stack is empty and FALSE if the stack is not empty.

(ii) Write the function pop in C. The function must perform the following three actions:

1. If the stack is empty, print a warning message and halt execution.

2. Remove the top element from the stack.

3. Return the top element of the stack to the calling function.

(iii) Write the function prcd(op1,op2) in C, where op1 and op2 are characters representing operators. The function prcd(op1,op2) must return TRUE if op1 has precedence over op2 when op1 appears to the left of op2 in an infix expression. The function prcd(op1,op2) returns FALSE otherwise.

 


Related Discussions:- Write the function pop in c

Deadlocks, What is methods For handling Deadlocks?

What is methods For handling Deadlocks?

Distinguish between passive and active attacks, QUESTION (a) Distinguis...

QUESTION (a) Distinguish between passive and active attacks. (b) Give two reasons why it is important to organise security awareness programs for users. (c) Explain how s

Basic parts of a computers, The basic parts of a computers are shown in Fig...

The basic parts of a computers are shown in Figure.   Input devices such as a keyboard, mouse or scanner are used to enter input (data and/or instructions), directly

Encoder, What is an encoder? Draw the logic circuit of Decimal to BCD encod...

What is an encoder? Draw the logic circuit of Decimal to BCD encoder and explain its working.?

Soft computing, Defination of Propositionl logic Predicate logic genertic a...

Defination of Propositionl logic Predicate logic genertic algorithm Hybrid system Optimization Fuzzy system rules Fuzzy system application

Concept in programming language, CONCEPT IN PROGRAMMING LANGUAGE: A Pr...

CONCEPT IN PROGRAMMING LANGUAGE: A Programming Language is used to design and describe a set of instructions and computations to be executed by a computer. To do programming,

Networks, Networks: There are different interpretations for the term °...

Networks: There are different interpretations for the term °nets% The Oxford English Dictionary states that 'a network is an interconnected chain or system of immaterial thing

Construct a conditional profits table, Question (a) A dairy wants to de...

Question (a) A dairy wants to determine the quantity of butter it should produce to meet the demand. Past records have shown the following demand pattern:

Write the function pop in c, QUESTION (a) Convert each of the following...

QUESTION (a) Convert each of the following expressions to prefix and postfix. (i) (A+B)*(C+D) (ii) A-B/(C*D^E) (^ denotes exponentiation) (b) The following algorithm c

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd