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

Electronic mail , Electronic mail is another PC to PC and PC to mainframe ...

Electronic mail is another PC to PC and PC to mainframe data exchange. If you subscribe to an electronic mail service, it will enable your PC to gain access to a 'mailbox' on a ma

COMPUTER SYSTEM ARCHITECTURE, PLEASE HELP ME TO CONSTRUCT THE XOR GATE USIN...

PLEASE HELP ME TO CONSTRUCT THE XOR GATE USING ONLY NAND GATE

Input Devices, Keyboards, microphones, and mice have generally been used as...

Keyboards, microphones, and mice have generally been used as the standard input devices for most computer systems. The popularity of video and computer games has led to the introdu

Indexing and abstracting databases, Indexing and Abstracting Databases: ...

Indexing and Abstracting Databases: A study of growth of indexing and abstracting services over the years would show that during the past two centuries, these services have be

What do you mean by an interrupt, Question 1 . Explain briefly the function...

Question 1 . Explain briefly the functional units of a computer Question 2 . What do you mean by an interrupt Question 3 . Explain fetching a word from the memory

Ms-powerpoint presentation for promoting national parks, Ms-PowerPoint Pres...

Ms-PowerPoint Presentation for Promoting National Parks You have been hired by Tourism Department to make a presentation to the travel agents from different countries. Design

Describe gamma and its importance, Question 1 Describe HSV and CMYK color ...

Question 1 Describe HSV and CMYK color models Question 2 Describe gamma and its importance Question 3 What are the steps involved in image manipulation? Que

Fourth generation of computers, THE FOURTH GENERATION (1975 ONWARDS) ...

THE FOURTH GENERATION (1975 ONWARDS) This generation of computers have one or more of the following characteristics:     Semi-conductor memory instead of core memo

Analyze the complexity of dijkstra''s algorithm, QUESTION (a) Given the...

QUESTION (a) Given the graph as shown in figure, apply Lagrangian technique to complete the table assuming μ=1 and T=14                        Path P

Computerised systems, Computerised Systems : You would have realized by no...

Computerised Systems : You would have realized by now that computing systems are most useful for manipulating information. Any organisation and management of information basically

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