Write the function pop in c, Basic Computer Science

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.

 

Posted Date: 10/29/2013 3:50:28 AM | Location : United States







Related Discussions:- Write the function pop in c, Assignment Help, Ask Question on Write the function pop in c, Get Answer, Expert's Help, Write the function pop in c Discussions

Write discussion on Write the function pop in c
Your posts are moderated
Related Questions
Nano programming using microcontrol and circuits

QUESTION (a) What is Multi-Protocol Label Switching (MPLS)? List the main advantage of running MPLS in a service provider network (b) What is a label? Explain the structure

Hi I have an assignment can you help me ?


SOCIAL NETWORKING:  A social network is a network of individuals which have some sort of interdependence on each other. This interdependence may be in the form of friendship,

The first reason to work with assembler is that it offers the opportunity of knowing more the operation of your PC, which permits the development of software in a more constant man

Definition of CPU scheduling: The assignment of physical processors to processes allows processors to complete work. The process of determining that for which process which pro

To find the minimum number of shelves in the loading process in cars

A rock weighs 33.6 N on Planet X and 49 N on Earth. What is g on Planet X

I NEED FLOW CHART ANT DRAWINGS OF BASIC OPERATIONS OF COMPUTER