Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions DS Programs/BT.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include<stdio.h>
#include<conio.h>
struct tree
{
int data;
struct tree *l,*r;
}*root,*q,*t,*p;
void insert()
{
int e;
struct tree *n=(struct tree*)malloc(sizeof(struct tree*));
printf("Enter data element:");
scanf("%d",&e);
n->data=e;
n->l=NULL;
n->r=NULL;
if(root==NULL)
root=n;
else
{
p=root;
q=root;
while(p!=NULL)
{
q=p;
if(p->data>e)
p=p->l;
else
p=p->r;
}
if(q->data>e)
q->l=n;
else
q->r=n;
}
}
void ino(struct tree *p)
{
while(p!=NULL)
{
ino(p->l);
printf("%5d",p->data);
ino(p->r);
}
}
void preo()
{
p=root;
while(p!=NULL)
{
printf("%5d",p->data);
preo(p->l);
preo(p->r);
}
}
void posto(struct tree *p)
{
while(p!=NULL)
{
posto(p->l);
posto(p->r);
printf("%5d",p->data);
}
}
void search()
{
int ele;
printf("Enter element to be searched:");
scanf("%d",&ele);
p=root;
while(p!=NULL)
{
if(p->data==ele)
{
printf("Element found!");
break;
}
else
{
if(ele>p->data)
p=p->r;
else
p=p->l;
}
}
if(p==NULL)
printf("Element not foumd!");
}
void main()
{
int o,ch;
do
{
printf("\nMENU\n1.Insert\n2.Inorder\n3.Preorder\n4.Postorder\n5.Search");
printf("\nEnter your choice:");
scanf("%d",&o);
switch(o)
{
case 1:insert();
break;
case 2:ino(root);
break;
case 3:preo();
break;
case 4:posto(root);
break;
case 5:search();
break;
}
printf("\n Enter 1 to continue:");
scanf("%d",&ch);
}while(ch==1);
getch();
}

96 changes: 96 additions & 0 deletions DS Programs/CQ.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include<stdio.h>
#include<conio.h>
#define M 5
int cq[M],f=-1,r=-1;
void ins(int val)
{
if((f==0&&r==M-1)||(r==f-1))
printf("\n Overflow!!");
else
{
if(f==-1&&r==-1)
{
f=0;
r=0;
}
else if(r==M-1&&f!=0)
r=0;
else
r++;
cq[r]=val;
}
}
int del()
{
if(f==-1&&r==-1)
{
printf("Underflow!");
return -1;
}
else
{
int v;
if(f==r)
{ v=cq[f];
f=-1;
r=-1;
}
else
{
v=cq[f];
f++;
}
return v;
}
}
void disp()
{ int d=f;
if(f==-1)
printf("No elements in queue!");
else
{
printf("Queue:\n");
while(1)
{
printf("%d\t",cq[d]);
if(d==M-1&&d!=r)
d=0;
else if(d==r)
break;
else
d++;
}}
}

void main()
{
int i,opt,ch,in,de;
do
{ clrscr();
printf("MENU\n1.Insert \n2.Delete \n3.Display");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Enter element to be inserted:");
scanf("%d",&in);
ins(in);
disp();
break;
case 2: de=del();
if(de==-1)
break;
else
printf("\nDeleted element is:%d",de);
disp();
break;
case 3: disp();
break;
}
printf("\nDo you want to continue?1/0");
scanf("%d",&opt);
}while(opt==1);
getch();
}


Binary file added DS Programs/P10_118A1079.docx
Binary file not shown.
Binary file added DS Programs/P5_118A1079.docx
Binary file not shown.
Binary file added DS Programs/P6_118A1079.docx
Binary file not shown.
Binary file added DS Programs/P7_118A1079.docx
Binary file not shown.
Binary file added DS Programs/P8_118A1079.docx
Binary file not shown.
Binary file added DS Programs/P9_118A1079.docx
Binary file not shown.
74 changes: 74 additions & 0 deletions DS Programs/PE.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#define m 10
char stack[m];
int top=-1;
void push(char ch)
{
if(top==m-1)
{
printf("Overflow!!");
}
else
{
top++;
stack[top]=ch;
}
}
char pop()
{
if(top==-1)
{
printf("Underflow!!");
return -1;
}
else
{
char c=stack[top];
top--;
return c;
}
}
int dop(int op1,int op2,char o)
{ int e;
if(o=='+')
e=op1+op2;
else if(o=='-')
e=op1-op2;
else if(o=='*')
e=op1*op2;
else if(o=='/')
e=op1/op2;
return e;
}

void main()
{
char s[10],o;
int a,b,i,l,r,ans;
clrscr();
printf("Enter postfix expression:");
scanf("%s",s);
l=strlen(s);
for(i=0;i<l;i++)
{
if(isdigit(s[i]))
push(s[i]);
else
{
a=pop();
a=a-'0';
b=pop();
b=b-'0';
r=dop(b,a,s[i]);
push(r);
}
}
ans=pop();
ans=ans-'0';
printf("RESULT::%d",ans);
getch();
}
41 changes: 41 additions & 0 deletions DS Programs/bs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include<stdio.h>
void main()
{
int a[10],e,p=0,n,i,j,l,h,m;
printf("Enter the number of elements in the array:");
scanf("%d",&n);
printf("Enter elements in array:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
l=0;
h=n-1;
printf("\nEnter element to be searched:");
scanf("%d",&e);
while(l<=h)
{
m=(l+h)/2;
if(a[m]==e)
{
printf("Element found at position:%d",m+1);
break;
}
else if(a[m]>e)
h=m;
else
l=m;
}
if(l>h)
printf("Element not found!");
}

OUTPUT:
Enter the number of elements in the array:6
Enter elements in array:1
3
5
7
9
11

Enter element to be searched:5
Element found at position:3
Loading