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

Types of chat room, Types of chat room: Java Chat rooms: The most comm...

Types of chat room: Java Chat rooms: The most common and popular chat scripts are based on java which is object oriented language. Java is freely available and comes with virt

Outline the five main steps in the web design process, QUESTION (a) Out...

QUESTION (a) Outline the five main steps in the Web Design Process (b) Draw an annotated diagram explaining how data is transmitted to web servers during a standard form sub

Statistics, Scores from a statistics exam are reported as deviation scores....

Scores from a statistics exam are reported as deviation scores. Which of the following deviation scores indicates a higher position in the class distribution?

Data autonomous transmission, DATA AUTONOMOUS TRANSMISSION: This could ...

DATA AUTONOMOUS TRANSMISSION: This could be the possible replacement for the ARINC 429 standard and will be annotated the standard - ARINC 629. In the DATAC system, the contro

Draw a neat diagram of the organization of computer, Question 1 Draw a nea...

Question 1 Draw a neat diagram of the organization of computer and explain about each unit Question 2 Explain batch processing system and multi-processing in brief Questi

Global positioning system, How does GPS work in the field of Sport or athle...

How does GPS work in the field of Sport or athletics?

Two dimensional arrays, Two dimensional Arrays:  A two-dimensional array ...

Two dimensional Arrays:  A two-dimensional array is like a table, with a defined number of rows, where each row has a defined number of columns. In some instances we need to  hav

7489 ttl ram device, The 7489 TTL Ram Device: The 7489 TTL Ram package ...

The 7489 TTL Ram Device: The 7489 TTL Ram package has 64 memory cells, each cell is capable of holding a single bit of data.  The cells are organised into locations, and each l

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