Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Name your program source files \"prog1.c\" and the executables \"prog1\" and sub

ID: 3556294 • Letter: N

Question

Name your program source files "prog1.c" and the executables "prog1" and substitute the number "1" for whatever the problem number is.

1. A dequeque might be described as a double-ended queque; that is, a structure in which elements can be inserted or removed from either end. Create a personal library (header and implementation files) containing types and functions for creating and maintaining a dequeue. Include functions for inserting and removing elements, for displaying individual nodes, and for displaying the dequeue, for displaying individual nodes, and for displaying the dequeue in reverse order.

2. A postfix expression is an expression in which each operator follows its operands. The table below shows several examples of postfix expressions.

The more familiar infix expression corresponding to each postfix expression is shown.

The advantage of postfix form is that there is no need to group subexpressions in parentheses or to consider operator precedence. The grouping marks in the table below are only for our convenience and are not required. Create a stack with push and pop functions to implement a calculator using postfix notation.

Your program should scan in an integer expression in postfix form and display the result. Your program should push each integre operand onto the stack. When an operator is encountered, the top two operands are popped, the operation is performed on its operands, and the result is pushed back onto the stack. The final result should be

the only value remaning on the stack when the end of the expression is reached. Write and use a function to print the result from the stack.

Value

5 6 *

4 5 6 * 3 / + 4 + ((5*6)/3 ) 14

Example Infix Expression   

Value

Explanation / Answer

/***********************************************************
*/


#define SIZE 50 /* Size of Stack */
#include <ctype.h>
int s[SIZE];
int top=-1; /* Global declarations */

push(int elem)
{ /* Function for PUSH operation */
s[++top]=elem;
}

int pop()
{ /* Function for POP operation */
return(s[top--]);
}

main()
{ /* Main Program */
char pofx[50],ch;
int i=0,op1,op2;
printf(" Read the Postfix Expression ? ");
scanf("%s",pofx);
while( (ch=pofx[i++]) != '')
{
if(isdigit(ch)) push(ch-'0'); /* Push the operand */
else
{ /* Operator,pop two operands */
op2=pop();
op1=pop();
switch(ch)
{
case '+':push(op1+op2);break;
case '-':push(op1-op2);break;
case '*':push(op1*op2);break;
case '/':push(op1/op2);break;
}
}
}
printf(" Given Postfix Expn: %s ",pofx);
printf(" Result after Evaluation: %d ",s[top]);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote