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

What is the use of system bus ?, The system bus is a cable which carries da...

The system bus is a cable which carries data communication among the major components of the computer, as well as the microprocessor. Not all of the communication that uses the bus

Describe CPU registers , The CPU has four internal registers, each of 16 bi...

The CPU has four internal registers, each of 16 bits. The first four, AX, BX, CX, and DX are common use registers and can also be used as 8 bit registers, if used in such a way it

Java programming, Write a program that lets the user play the game Rock, Pa...

Write a program that lets the user play the game Rock, Paper, Scissors against the computer. The program should work as follows: ? When the program begins, the results of the prev

Finite automata, find the regular expression of(a/?)(a/b)?

find the regular expression of(a/?)(a/b)?

Mini computers and micro computers, Mini Computers and Micro Computers: ...

Mini Computers and Micro Computers: The mini computers are intermediate in power, and may function as small mainframe computers. They are often dedicated to a particular purpo

Explain briefly about das, Question 1 What is Content Addressable Storage?...

Question 1 What is Content Addressable Storage? Explain the elements of Content Addressable Storage Question 2 Explain briefly about DAS Question 3 Explain about N

Write the steps to use the network setup wizard, Question 1 Elaborate the ...

Question 1 Elaborate the various steps in performing a Mail Merge. Execute one mail merge operation for sending invitation for a conference which is being conducted in your organi

Finding average marks, Problem In the Excel sheet, input the marks of a...

Problem In the Excel sheet, input the marks of any 5 students with 5 subjects and find the average marks, maximum marks, minimum marks obtained by the student. Using Excel s

Explian, explain anatomy of digital coputer

explain anatomy of digital coputer

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