Professional Documents
Culture Documents
Lab 3 19 BCE1096
Lab 3 19 BCE1096
Lab 3 19 BCE1096
Write a program to convert the expression from infix to postfix form and evaluate the
same using stack data structure.
#include<stdio.h>
int stack[20];
int pop();
void infix_to_postfix();
int main()
char temp;
top = -1;
scanf("%s", infix_string);
infix_to_postfix();
char next;
char symbol;
switch(symbol)
break;
case ')':
postfix_string[temp++] = next;
break;
case '+':
case '-':
case '*':
case '/':
case '%':
case '^':
postfix_string[temp++] = pop();
push(symbol);
break;
default:
postfix_string[temp++] = symbol;
while(!isEmpty())
postfix_string[temp++] = pop();
postfix_string[temp] = '\0';
switch(symbol)
case '-': return 1; case '*': case '/': case '%': return 2; case '^': return 3; default: return 0; }
return 1; }
else
{
return 0; }
top = top + 1;
stack[top] = symbol; }
int isEmpty() {
if(top == -1) {
return 1; }
else
return 0; }
int pop()
if(isEmpty())
Practice Question 3:
Assume you have two queues QQ1 and QQ2. Write a function called match that will
count how many elements in the same position of the two queues are equal. The
queues may not be the same length. Do not modify the queues. Use the queue member
functions to access the queues.
Input Format:
Get the length of QQ1, followed by elements in QQ1.
Get the length of QQ2, followed by elements in QQ2.
Output Format:
Number of elements in the same position, followed by the elements that match
###Sample Input:
###Sample Output:
2, 5 and 9 // The number of elements followed by the elements that match.
#include<stdio.h>
void main(){
for(i=0;i<l1;i++){
scanf("%d",&QQ1[i]); }
for(i=0;i<l2;i++){
scanf("%d",&QQ2[i]); }
if(QQ1[i]==QQ2[i]){ count++;
ans[j]=QQ1[i];
j++; }
printf("%d,",count); for(k=0;k<j;k++){
printf("%d\t",ans[k]); }
}