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

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

What is Assembly Language?, Assembly language is fundamentally the local la...

Assembly language is fundamentally the local language of your computer. In principle the processor of your machine understands machine code (consisting of ones and zeroes). But wit

Prelude to programming concepts and design 5th edition, Input a list of pos...

Input a list of positive numbers, terminated by 0, into an array numbers []. Then display the array and the largest and smallest number in it.

Flowcharting, Flowcharting: Flowcharting: A Flowchart is a graphical r...

Flowcharting: Flowcharting: A Flowchart is a graphical representation of an algorithm. It can be compared to the blueprint of a building. Just as a building contractor refers

Storage capacity and cost per bit of storage, Storage capacity and Cost per...

Storage capacity and Cost per bit of storage: Storage capacit y:  It is the amount of data that can be stored in the storage unit. A large capacity is preferred.  Cost pe

Discrete Math, 3. Let f, g: R?R, where g(x) 1 - x + x2 and f (x)=ax + b. I...

3. Let f, g: R?R, where g(x) 1 - x + x2 and f (x)=ax + b. If (g ? f )(x)= 9x2 - 9x + 3, determine a, b.

Cryptography, Consider the one-time pad encryption scheme to encrypt a 1-bi...

Consider the one-time pad encryption scheme to encrypt a 1-bit message m, and assume m is chosen with uniform distribution from message space M={0,1}. Let E1 be the event "message

Simple Algorithm, How to make an assignment entitled "Decision Making: Fore...

How to make an assignment entitled "Decision Making: Forecasting" and I am required to make a pseudocode and flowchart based on the task.

COMPUTER ORGANIZATION, Ask questio2. Define interrupt n #Minimum 100 words ...

Ask questio2. Define interrupt n #Minimum 100 words accepted#

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