dsa 2
dsa 2
dsa 2
Output:
PROGRAM – 4
Write a program to demonstrate the use of stack (implemented using linear
array) in converting arithmetic expression from infix notation to postfix
notation.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int precedence(char c) {
if (c == '^')
return 3;
else if (c == '*' || c == '/')
return 2;
else if (c == '+' || c == '-')
return 1;
else
return -1;
}
int main() {
char infix[] = "(A+(B*C-(D/E^F)*G)*H)";
printf("Infix Expression: %s\n", infix);
infixToPostfix(infix);
return 0;
}
Output:
PROGRAM – 5
Program to demonstrate the use of stack (implemented using linear linked
lists) in evaluating arithmetic expression in postfix notation.
#include <stdio.h>
#include <stdlib.h>
int main() {
char postfix[100];
printf("Enter a postfix expression: ");
fgets(postfix, sizeof(postfix), stdin);
postfix[strlen(postfix) - 1] = '\0';
int result = evaluatePostfix(postfix);
printf("Result: %d\n", result);
return 0;
}
OUTPUT:
PROGRAM – 6
Program to demonstration the implementation of various operations on a
linear queue represented using a linear array.
//Enqueue
#include <stdio.h>
int main(){
int que[10]={12,43,75,23,53,85,23};
int front=0;
int rear=6;
if(rear==sizeof(que)-1){
printf("OVERFLOW");
}
else {
rear++;
printf("Enter the no. to Enqueue : ");
scanf("%d",&que[rear]);
}
for(int i=0;i<rear+1;i++){
printf("%d\t",que[i]);
}
return 0;
}
OUTPUT:
//Dequeue
#include <stdio.h>
int main(){
int que[10]={12,43,75,23,53,85,23};
int front=0;
int rear=7;
if(front==-1){
printf("UNDERFLOW");
}
else {
front++;
}
for(int i=front;i<rear;i++){
printf("%d\t",que[i]);
}
return 0;
}
OUTPUT: