DDS PRACTCAL
DDS PRACTCAL
1. #include<stdio.h>
int stack[100],choice,n,top,x,i;
void push(void);
void pop(void);
void display(void);
void main()
top=-1;
scanf("%d",&n);
printf("\n\t--------------------------------");
do
scanf("%d",&choice);
switch(choice)
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
break;
}
default:
while(choice!=4);
void push()
if(top>=n-1)
else
scanf("%d",&x);
top++;
stack[top]=x;
void pop()
if(top<=-1)
else
top--;
void display()
if(top>=0)
{
printf("\n The elements in STACK \n");
printf("\n%d",stack[i]);
else
OUTPUT:
2. #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
switch (operator) {
case '+':
case '-':
return 1;
case '*':
case '/':
return 2;
case '^':
return 3;
default:
return -1;
// is an operator
// to postfix expression
int i, j;
if (!postfix) {
char stack[MAX_EXPR_SIZE];
continue;
postfix[j++] = infix[i];
stack[++top] = infix[i];
postfix[j++] = stack[top--];
else
top--;
else if (isOperator(infix[i])) {
postfix[j++] = stack[top--];
stack[++top] = infix[i];
if (stack[top] == '(') {
postfix[j++] = stack[top--];
postfix[j] = '\0';
return postfix;
// Driver code
int main()
{
// Function call
printf("%s\n", postfix);
} else {
printf("%s\n", postfix);
free(postfix);
return 0;
OUTPUT:
3. #include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int stack[MAXSTACK];
printf("stack overflow\n");
exit(1);
else {
stack[++top] = item;
int pop()
if (top < 0) {
printf("stack underflow\n");
exit(1);
else {
return stack[top--];
int i;
char ch;
int val;
int A, B;
ch = postfix[i];
if (isdigit(ch)) {
ch - '0' is used for getting digit rather than ASCII code of digit */
push(ch - '0');
}
/* we saw an operator
A = pop();
B = pop();
case '*':
val = B * A;
break;
case '/':
val = B / A;
break;
case '+':
val = B + A;
break;
case '-':
val = B - A;
break;
push(val);
int main()
char postfix[POSTFIXSIZE];
printf("ASSUMPTION: There are only four operators (*, /, +, -) in an expression and operand is
single digit only.\n");
int i = 0;
char ch;
while (i < POSTFIXSIZE - 1 && (ch = getchar()) != ')') {
postfix[i++] = ch;
EvalPostfix(postfix);
return 0;
OUTPUT:
4. #include <stdio.h>
if (n == 1)
return;
}
towerOfHanoi(n - 1, A, C, B);
towerOfHanoi(n - 1, B, A, C);
int main()
return 0;
OUTPUT:
5. #include <stdio.h>
#include <stdlib.h>
void enqueue();
void dequeue();
void show();
int inp_arr[SIZE];
void main()
int ch;
while (1)
printf("4. Exit\n");
scanf("%d", &ch);
switch (ch)
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
show();
break;
case 4:
exit(0);
default:
void enqueue()
int insert_item;
if (Rear == SIZE - 1)
printf("Overflow \n");
else
if (Front == -1)
Front = 0;
scanf("%d", &insert_item);
Rear = Rear + 1;
inp_arr[Rear] = insert_item;
void dequeue()
printf("Underflow \n");
return;
else
Front = Front + 1;
void show()
if (Front == -1)
else
printf("Queue: \n");
printf("\n");
Output: