Dsa Iot Manual (New) .............
Dsa Iot Manual (New) .............
three fields. The first field is the name of the Day (A dynamically allocated
String), The second field is the date of the Day (A integer), the third field is the
#include <stdio.h>
#include <string.h>
struct Day {
char name[20];
int date;
char activity[100];
};
int main() {
strcpy(calendar[0].name, "Monday");
calendar[0].date = 1;
strcpy(calendar[1].name, "Tuesday");
calendar[1].date = 2;
strcpy(calendar[2].name, "Wednesday");
calendar[2].date = 3;
strcpy(calendar[3].name, "Thursday");
calendar[3].date = 4;
calendar[4].date = 5;
strcpy(calendar[5].name, "Saturday");
calendar[5].date = 6;
strcpy(calendar[6].name, "Sunday");
calendar[6].date = 7;
printf("Calendar:\n");
calendar[i].activity);
return 0;
OUTPUT:-
Calender:
b. Write functions create (), read () and display (); to create the calendar, to read
the data from the keyboard and to print weeks activity details report on
screen.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct CalendarDay {
char *dayName;
int date;
char *activity;
};
calendar[i].dayName = (char*)malloc(20);
calendar[i].activity = (char*)malloc(100);
scanf("%s", calendar[i].dayName);
scanf("%d", &calendar[i].date);
int main() {
create(calendar);
read(calendar);
display(calendar);
free(calendar[i].dayName);
free(calendar[i].activity);
return 0;
OUTPUT:-
date : 01
Activity : Waking up
date : 02
Activity : brushing
date : 03
Activity : bathing
date : 04
Activity : eating
date : 05
Activity : watching tv
date : 06
Activity : crying
date : 07
Activity : sleeping
b) Perform Pattern Matching Operation: Find and Replace all occurrences of PAT
in STR with REP if PAT exists in STR. Report suitable messages in case PAT
Support the program with functions for each of the above operations. Don't use Built-in
functions
#include<stdio.h>
void main()
int i,j,c,m,k,flag=0;
gets(STR);
gets(PAT);
gets(REP);
i=m=c=j=0;
while(STR[c]!='\0')
if(STR[m]==PAT[i])
i++;
m++;
flag=1;
if(PAT[i]=='\0')
ans[j]=REP[k];
i=0;
c=m;
else
ans[j]=STR[c];
j++;
c++;
m=c;
i=0;
if(flag==0)
else
ans[j]='\0';
OUTPUT : -
Good Morning.
morning
evening
f. Exit
Support the program with appropriate functions for each of the above operations.
#include<stdio.h>
#include<stdlib.h>
#define MAX 20
void main()
for(;;)
printf("\nMenu\n");
scanf("%d", &ch);
switch(ch)
case 1:
if(stack_full(top))
printf("Stack Full\n");
else
printf("Enter an Element\n");
scanf("%d", &ele);
break;
case 2:
if(stack_empty(top))
printf("Stack Empty\n");
else
break;
case 3:
if(stack_empty(top))
printf("Stack Empty\n");
printf("Stack is Palindrome\n");
display(stack, top);
else
break;
case 4:
if(stack_empty(top))
printf("Stack Empty\n");
else if(stack_full(top))
printf("Stack Full\n");
else
break;
case 5:
if(stack_empty(top))
printf("Stack Empty\n");
else
display(stack, top);
break;
case 6:
exit(0);
if(top == MAX-1)
return 1;
return 0;
if(top ==-1)
return 1;
return 0;
stack[++(*top)] = ele;
{
return stack[(*top)--];
int i, not_palindrome=0;
if(stack[i] != stack[top-i])
not_palindrome = 1;
break;
if(not_palindrome)
return 0;
else
return 1;
int i;
printf("\n");
}
OUTPUT :-
Menu
1.Push
2.Pop
3.Check Palindrome
4.Stack Status
5.Display
6.Exit
Enter an element
10
Menu
1.Push
2.Pop
3.Check Palindrome
4.Stack Status
5.Display
6.Exit
Enter an element
20
Menu
1.Push
2.Pop
3.Check Palindrome
4.Stack Status
5.Display
6.Exit
2
Deleted Element is 20
Menu
1.Push
2.Pop
3.Check Palindrome
4.Stack Status
5.Display
6.Exit
Menu
1.Push
2.Pop
3.Check Palindrome
4.Stack Status
5.Display
6.Exit
Menu
1.Push
2.Pop
3.Check Palindrome
4.Stack Status
5.Display
6.Exit
10
Menu
1.Push
2.Pop
3.Check Palindrome
4.Stack Status
5.Display
6.Exit
#define SIZE 50
#include <ctype.h>
#include <stdio.h>
char s[SIZE];
s[++top] = elem;
char pop()
return (s[top--]);
switch (elem)
case '#':return 0;
case '(':return 1;
case '+':
case '-':return 2;
case '*':
case '/':
case '%':return 3;
case '^':return 4;
void main()
int i = 0, k = 0;
clrscr();
scanf("%s", infx);
push('#');
if (ch == '(')
push(ch);
else if (isalnum(ch))
pofx[k++] = ch;
pofx[k++] = pop();
elem = pop();
else
pofx[k++] = pop();
push(ch);
pofx[k++] = pop();
pofx[k] = '\0';
getch();
OUTPUT :-
a.Evaluation of Suffix expression with single digit operands and operators: +,-,*,/,%,^.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
top = top+1;
s[top] = item;
int pop()
int item;
item = s[top];
top = top-1;
return item;
void main()
scanf("%s", postfix);
symb =postfix[i];
if(isdigit(symb))
push(symb- '0');
else
{
op2 =pop();
op1 = pop();
switch(symb)
case '+':
push(op1+op2);
break;
case '-':
push(op1-op2);
break;
case '*':
push(op1*op2);
break;
case '/':
push(op1/op2);
break;
case '%':
push(op1%op2);
break;
case '$':
case '^':
push(pow(op1, op2));
break;
default : push(0);
}
res = pop();
OUTPUT :-
657-+/82+*3$5
Result =21957
623+-382/+2$3+
Result = 172
Program 5b:
#include<stdio.h>
#include<math.h>
if(n == 0)
return;
void main ()
int n;
printf("\nEnter the number of discs: \n\n");
scanf("%d", &n);
OUTPUT:
Program 6:
Develop a menu driven Program in C for the following operations on Circular QUEUE of
Supportthe program with appropriate functions for each of the above operations.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define SIZE 5
int main( )
for(;;)
scanf("%d",&option);
switch(option)
case 1:
if(count==SIZE)
printf("\n Q is Full\n");
else
r=(r+1)%SIZE;
scanf("%d",&q[r]);
count++;
break;
case 2:
if(count==0)
printf("\nQ is empty\n");
else
count--;
f=(f+1)%SIZE;
break:
case 3:
if(count==0)
printf("\nQ is Empty\n");
else
i=f;
for(j=0;j<count;j++) {
break;
default: exit(0);
Output:
20
Program 7:
Develop a menu driven Program in C for the following operations on Singly Linked List (SLL) of Student
Data with the fields: USN, Name, Programme, Sem, PhNo
e. Exit
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
int usn;
char name[20];
char branch[20];
int semester;
char phone[20];
}STUDENT;
struct node{
int usn;
char name[20];
char branch[20];
int semester;
char phone[20];
};
NODE getnode(){
NODE x;
x=(NODE)malloc(sizeof(struct node));
if(x==NULL){
printf("out of memory\n");
exit(0);
return x;
temp->usn=item.usn;
strcpy(temp->name,item.name);
strcpy(temp->branch,item.branch);
temp->semester=item.semester;
strcpy(temp->phone,item.phone);
temp->link=NULL;
if(first==NULL)
return temp;
temp->usn=item.usn;
strcpy(temp->name,item.name);
strcpy(temp->branch,item.branch);
temp->semester=item.semester;
strcpy(temp->phone,item.phone);
temp->link=NULL;
if(first==NULL)
while(cur->link!=NULL){
cur=cur->link;
cur->link=temp;
return first;
NODE temp;
if(first==NULL){
temp=first;
temp=temp->link;
free(first);
return temp;
NODE cur,prev;
if(first==NULL){
return first;
if(first->link==NULL){
free(first);
return NULL;
prev=NULL;
cur=first;
while(cur->link!=NULL){
prev=cur;
cur=cur->link;
free(cur);
prev->link=NULL; return first;
if(first==NULL){
return;
cur=first;
while(cur!=NULL){
printf("%d\t%s\t%s\t%d\t%s\t\n",cur->usn,cur->name,cur->branch,cur->semester,cur-
>phone);
cur=cur->link;
count++;
printf("numbrt of students=%d\n",count);
void main(){
NODE first;
int choice;
STUDENT item;
first=NULL;
for(;;){
printf("1.insert_front\n2.insert_rear\n3.delete_front\n4.delete_rear\n5.display\n6.exit\n");
scanf("%d",&choice);
switch(choice){
case 1: printf("USN :\n");
scanf("%d",&item.usn);
printf("name :\n");
scanf("%s",item.name);
printf("branch :\n");
scanf("%s",item.branch);
printf("semester:\n");
scanf("%d",&item.semester);
printf("phone :\n");
scanf("%s",item.phone);
first=insert_front(item,first);
break;
scanf("%d",&item.usn);
printf("name :\n");
scanf("%s",item.name);
printf("branch :\n");
scanf("%s",item.branch);
printf("semester:\n");
scanf("%d",&item.semester);
printf("phone :\n");
scanf("%s",item.phone);
first=insert_rear(item,first);
break;
case 3: first=delete_front(first);
break;
case 4: first=delete_rear(first);
break;
case 5: display(first);
break;
default:exit(0);
OUTPUT:
1.insert_front
2.insert_rear
3.delete_front
4.delete_rear
5.display
6.exit
USN :
12
name :
ram
branch :
iot
semester:
phone :
9875423610
1.insert_front
2.insert_rear
3.delete_front
4.delete_rear
5.display
6.exit
USN :
14
name :
raj
branch :
cs
semester:
phone :
7584236915
1.insert_front
2.insert_rear
3.delete_front
4.delete_rear
5.display
6.exit
14 raj cs 3 7584236915
numbrt of students=2
1.insert_front
2.insert_rear
3.delete_front
4.delete_rear
5.display
6.exit
1.insert_front
2.insert_rear
3.delete_front
4.delete_rear
5.display
6.exit
Program 8:-
Develop a menu driven Program in C for the following operations on Doubly Linked List (DLL) of
Employee Data with the fields: SSN, Name, Dept, Designation, Sal, PhNo
f. Exit
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Enode{
char ssn[15];
char name[20];
char dept[5];
char designation[10];
int salary;
}*head=NULL;
void del_beg();
void del_end();
void display();
int count=0;
void main(){
int choice;
char s[15],n[20],dpt[5],des[10];
int sal;
while(1){
switch(choice){
case 1:
scanf("%s%s%s%s%d%lld",s,n,dpt,des,&sal,&p); create(s,n,dpt,des,sal,p);
break;
case 2:
display();
break;
case 3:
scanf("%s%s%s%s%d%lld",s,n,dpt,des,&sal,&p);
ins_beg(s,n,dpt,des,sal,p);
break;
case 4:
scanf("%s%s%s%s%d%lld",s,n,dpt,des,&sal,&p); ins_end(s,n,dpt,des,sal,p);
break;
case 5:
del_beg();
break;
case 6:
del_end();
break;
case 7:
exit(0);
}
}
void create(char s[15],char n[20],char dpt[5],char des[10],int sal,long long int p){
if(head==NULL){
strcpy(head->ssn,s);
strcpy(head->name,n);
strcpy(head->dept,dpt);
strcpy(head->designation,des);
head->salary=sal;
head->phno=p;
head->left=NULL; head->right=NULL;
tail=head;
else{
strcpy(temp1->ssn,s);
strcpy(temp1->name,n);
strcpy(temp1->dept,dpt);
strcpy(temp1->designation,des);
temp1->salary=sal;
temp1->phno=p; tail->right=temp1;
temp1->right=NULL;
temp1->left=tail;
tail=temp1;
void display(){
temp1=head;
while(temp1!=NULL){
printf(" \n");
printf("%s\n%s\n%s\n%s\n%d\n%lld\n",temp1->ssn,temp1->name,temp1->dept,temp1-
>designation,temp1->salary,temp1->phno);
void ins_beg(char s[15],char n[20],char dpt[5],char des[10],int sal,long long int p){
strcpy(temp1->ssn,s);
strcpy(temp1->name,n);
strcpy(temp1->dept,dpt);
strcpy(temp1->designation,des);
temp1->salary=sal;
temp1->phno=p;
temp1->right=head;
head->left=temp1;
head=temp1;
temp1->left=NULL;
void ins_end(char s[15],char n[20],char dpt[5],char des[10],int sal,long long int p){
strcpy(temp1->ssn,s);
strcpy(temp1->name,n);
strcpy(temp1->dept,dpt);
strcpy(temp1->designation,des);
temp1->salary=sal;
temp1->phno=p;
tail->right=temp1;
temp1->left=tail;
temp1->right=NULL;
tail=temp1;
void del_beg(){
temp1=head->right;
free(head); head=temp1;
head->left=NULL;
void del_end(){
temp1=tail->left;
free(tail);
tail=temp1;
tail->right=NULL;
OUTPUT:
Program 9:
Develop a Program in C for the following operations on Singly Circular Linked List(SCLL) with header
nodes a. Represent and Evaluate a Polynomial P(x,y,z) = 6x2y 2z-4yz5+3x3yz+2xy5z-2xyz3
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int val;
struct node
};
NODE *first;
NODE *temp,*cur;
temp->coef=coef;
temp->px=px;
temp->py=py;
temp->pz=pz;
if(first==NULL
temp->next=temp;
first=temp;
return;
if(first->next==first)
first->next=temp;
temp->next=first;
cur=first;
while(cur->next!=first)
cur=cur->next;
cur->next=temp;
temp->next=first;
return;
void display()
NODE *cur;
if(first==NULL
printf("List is empty\n");
return;
cur=first;
while(cur->next!=first)
printf("%d ",cur->coef);
printf(" x^%d",cur->px);
printf(" y^%d",cur->py);
cur=cur->next;
printf("%d ",cur->coef);
printf(" x^%d",cur->px);
printf(" y^%d",cur->py);
printf(" z^%d\n",cur->pz);
return;
if(first==NULL)
printf("List is empty\n");
return 0;
cur=first;
while(cur->next!=first)
s=s+v;
cur=cur->next;
s=s+v;
return s;
int main()
int coef,px,py,pz,
x,y,z,i;
int val;
first=NULL;
while(1)
printf("2. Display\n");
printf("3. Evaluate\n");
printf("4. Exit\n");
scanf("%d",&i);
switch(i)
scanf("%d",&coef);
scanf("%d%d%d",&px, &py,&pz);
insert(coef,px,py,pz);
break;
case 2 : display();
break;
case 3 :
scanf("%d%d%d",&x,&y,&z);
val=evaluate(x,y,z);
printf("\nValue=%d\n",val);
break;
case 4 :
return 0;
default :
printf(" Wrong choice. Enter 1,2 3\n");
break;
OUTPUT:-
2. Display
3. Evaluate
4. Exit
Enter Choice = 1
Enter Coefficient = 4
2. Display
3. Evaluate
4. Exit
Enter Choice = 1
Enter Coefficient = 5
2. Display
3. Evaluate
4. Exit
Enter Choice = 1
Enter Coefficient = 3
2. Display
3. Evaluate
4. Exit
Enter Choice = 1
Enter Coefficient = 6
2. Display
3. Evaluate
4. Exit
Enter Choice = 2
4 x^3 y^3 z^2 + 5 x^3 y^2 z^2 + 3 x^2 y^2 z^2 + 6 x^1 y^1 z^1
2. Display
3. Evaluate
4. Exit
Enter Choice = 3
Value = 6120
2. Display
3. Evaluate
4. Exit
Enter Choice = 4
PROGRAM 9b:-
b. Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z) and store theresult in
POLYSUM(x,y,z). Support the program with appropriate functions for each of the above operations.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct node
};
int i,n,cf,px,py,pz;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d %d %d %d",&cf,&px,&py,&pz);
insert(head,cf,px,py,pz);
}
return head;
NODE cur,tmp;
cur=head->link;
tmp->coef=cof;
tmp->px=x;
tmp->py=y;
tmp->pz=z;
tmp->flag=0;
while(cur->link!=head)
cur=cur->link;
cur->link=tmp;
tmp->link=head;
while(cur1 != h1)
if(cur2 == h2)
cur2=h2->link;
while(cur2 != h2)
{
scf=cur1->coef+cur2->coef;
insert(h3,scf,cur1->px,cur1->py,cur1->pz);
cur2->flag=1;
cur2=h2->link;
break;
cur2=cur2->link;
if(cur1 == h1)
break;
if(cur2 == h2)
insert(h3,cur1->coef,cur1->px,cur1->py,cur1->pz);
cur1=cur1->link;
cur2=h2->link;
while(cur2 != h2)
if(cur2->flag==0)
insert(h3,cur2->coef,cur2->px,cur2->py,cur2->pz);
cur2=cur2->link;
return h3;
}
NODE cur;
if(head->link==head)
printf("List is empty\n");
return;
cur=head->link;
while(cur != head)
if(cur->coef > 0)
cur=cur->link;
printf("\n");
void main()
head1=(NODE)malloc(sizeof(struct node));
head1->link=head1;
head2=(NODE)malloc(sizeof(struct node));
head2->link=head2;
head3=(NODE)malloc(sizeof(struct node));
head3->link=head3;
head1=create_list(head1);
head2=create_list(head2);
printf("\nPolynomial 1 is :");
display(head1);
printf("\nPolynomial 2 is :");
display(head2);
head3=add_poly(head1,head2,head3);
display(head3);
OUTPUT:-
1.Create Polynomial 1
2.Create Polynomial 2
Enter the number of terms : 2
PROGRAM 10:-
Develop a menu driven Program in C for the following operations on Binary Search Tree (BST)of
Integers. a. Create a BST of N Integers: 6, 9, 5, 2, 8, 15, 24, 14, 7, 8, 5, 2
c. Search the BST for a given element (KEY) and report the appropriate message
d. Exit
#include <stdio.h>
#include <stdlib.h>
struct BST
int data;
};
NODE *node;
if (node == NULL)
{
NODE *temp;
temp= (NODE*)malloc(sizeof(NODE));
temp->data = data;
return temp;
if(data<(node->data))
node->left=createtree(node->left, data);
else if(data>node->data)
return node;
if(node == NULL)
node->left=search(node->left, data);
}
else if(data > node->data)
node->right=search(node->right, data);
else
return node;
if(node != NULL)
inorder(node->left);
printf("%d\t", node->data);
inorder(node->right);
if(node!=NULL)
printf("%d\t", node->data);
preorder(node->left);
preorder(node->right);
}
}
if(node != NULL)
postorder(node->left);
postorder(node->right);
printf("%d\t", node->data);
void main()
NODE *root=NULL;
while (1)
printf("\n3.Inorder\n4.Preorder\n5.Postorder\n6.Exit");
scanf("%d", &ch);
switch (ch)
case 1:
for(i=0;i<n;i++)
scanf("%d", &data);
root=createtree(root, data);
break;
case 2:
scanf("%d", &data);
root=search(root, data);
break;
case 3:
inorder(root);
break;
case 4:
preorder(root);
break;
case 5:
postorder(root);
break;
case 6:exit(0);
default:
printf("\nWrong option");
break;
}}}
OUTPUT:-
3.Inorder
4.Preorder
5.Postorder
6.Exit
Enter N value: 5
28465
3.Inorder
4.Preorder
5.Postorder
6.Exit
3.Inorder
4.Preorder
5.Postorder
6.Exit
3.Inorder
4.Preorder
5.Postorder
6.Exit
Inorder Traversal:
2 4 5 6 8
3.Inorder
4.Preorder
5.Postorder
6.Exit
2 8 4 6 5
3.Inorder
4.Preorder
5.Postorder
6.Exit
Postorder Traversal:
5 6 4 8 2
3.Inorder
4.Preorder
5.Postorder
6.Exit
PROGRAM 11:-
Design, develop and implement a Program in C for the following operations on Graph (G) of Cities Create
a Graph of N cities using Adjacency Matrix. Print all the nodes reachable from agiven starting node in a
digraph using BFS method.
#include<stdio.h>
#include<stdlib.h>
int n, a[10][10],i,j,source,s[10],choice,count;
void bfs(int n,int a[10][10],int source,int s[])
int q[10],u;
int front=1,rear=1;
s[source]=1;
q[rear]=source;
while(front<=rear)
u=q[front];
front=front+1;
for(i=1;i<=n;i++)
rear=rear+1;
q[rear]=i;
s[i]=1;
int main()
scanf("%d",&n);
for(i=1;i<=n;i++)
for (j=1;j<=n;j++)
scanf("%d",&a[i][j]);
while(1)
printf("1.BFS\n 2.Exit\n");
scanf("%d",&choice);
switch(choice)
scanf("%d",&source);
for(i=1;i<=n;i++)
s[i]=0;
bfs(n,a,source,s);
for(i=1;i<=n;i++)
if(s[i]==0)
else
break;
case 2:
exit(0);
}}}
OUTPUT:-
01010
00100
10000
00100
00110
1.BFS
2.Exit
1.BFS
2.Exit
PROGRAM 12:-